File storage

The file storage server plugin provides an interface to store, download on the server and provide download links to files stored on a safe storage backend of the developer’s choice.

Available backend storage providers are currently S3 and AzureBlobStorage.

Configuring the plugin

"fileStorage": {
    "provider":"s3",
    "s3":{
        "bucket":"s3bucketname",
        "accessKeyId":"id of the access key to use",
        "secretKey":"secret key"
    },
    "azureBlob":{
       "connectionString":"blob storage connection string",
       "container":"containe name"
    }
}

The configuration above configures both azure blob & s3 storage providers, but configures the file storage system to use s3.

provider: possible values are s3 and azure

Using the plugin

To use the plugin, import the IFileStorage interface by adding it to a class registered in the dependency scope.

public interface IFileStorage
{
    /// <summary>
    /// Uploads a file to the storage backend
    /// </summary>
    /// <param name="path">path of the file in the storage backend</param>
    /// <param name="content">A stream which contains the content</param>
    /// <param name="mimeType">The content type</param>
    /// <returns></returns>
    Task UploadFile(string path, Stream content, string mimeType);

    /// <summary>
    /// Downloads a file from the storage
    /// </summary>
    /// <param name="path">Path of the file</param>
    /// <returns>An object containing a stream to get the data and its content type.</returns>
    Task<FileDescription> DownloadFile(string path);

    /// <summary>
    /// Gets a download url for a file
    /// </summary>
    /// <param name="path">Path of the file</param>
    /// <remarks>
    /// The url can be used by clients.
    /// </remarks>
    /// <returns>The url</returns>
    Task<Uri> GetDownloadUrl(string path);

    /// <summary>
    /// Deletes a file from the storage backend
    /// </summary>
    /// <param name="path">Path of the file</param>
    /// <returns></returns>
    Task DeleteFile(string path);
}