Go to content

Bulletcode.NET

Storage

Bulletcode.NET includes a service for storing files in the Azure blob container or the local file system. Call the AddStorageService() extension method of the IServiceCollection to enable this service:

services.AddStorageService();

The StorageOptions class contains settings for the storage service. They can be changed by passing a callback to the AddStorageService() method, or by adding a StorageOptions section to the appsettings.json file.

  • ConnectionString — specifies the connection string for the Azure storage account.
  • AccountName — specifies the account name for the blob container.
  • ContainerName — specifies the name of the blob container.
  • LocalPath — specifies the local path of the file system directory used for storing files. It can be a relative or absolute path. The default value is "storage".

In order to use the Azure blob container, specify either the connection string or the account name, and the container name. Otherwise, the local file system will be used.

NOTE

The local storage should only be used during development. Using the Azure blob container is recommended for production purposes.

When the account name is specified, the "https://{AccountName}.blob.core.windows.net/{ContainerName}" URL is used for the blob container.

The IStorageService has the following methods:

  • UploadAsync() — uploads a file with the specified name and content to the storage. An optional hot or cold access tier and an optional dictionary containing tags can be specified; these options are ignored when using the local file system.
  • DownloadAsync() — downloads the file with the specified name from the storage.
  • DeleteAsync() — deletes the file with the specified name from the storage.