Using the File Storage Provider (C#Bot)
When using the
image attributes in a model for C#Bot it is important to understand how the files are stored.
File Storage Providers
When a file is stored by C#Bot, the content will not be saved to the database and instead, saved using a File Storage Provider. The provider which is used can be configured in your appsettings file. A file system provider is an abstraction over any system that can store files. This includes sources such as a network attached drive, a cloud based blob storage service or even an in memory dictionary.
Currently there are two different file storage providers in C#Bot:
- File System (Default)
- Amazon S3
More file system providers will be added over time and can be created by implementing the
IUploadStorageProvider interface on the server-side, and updating the configuration. Creating a custom provider will be covered more in another article.
Configuring File Storage Providers
File system providers can be configured in appsettings for a particular project. There is configuration sections for both picking which provider to use, as well as to configure individual providers. For this we will be changing
appsettings.xml however, these settings can be applied in command line args or via environment variables.
Picking a provider
A storage provider can be picked by adding the following section to your
appsettings.xml file. All configuration should be done in the protected region labelled
Add any extra app configuration here.
<StorageProvider> <Provider>FILE_SYSTEM</Provider> </StorageProvider>
This will configure the server to use the local file system for storing files. The valid values for the
Provider key are
S3 by default. If no provider is set then
FILE_SYSTEM will be used.
File System Provider Configuration
The file system storage provider supports changing the root folder to another location. By default this value will be
___data in the current working directory for the server.
<FileSystemStorageProvider> <RootFolder>/path/to/folder</RootFolder> </FileSystemStorageProvider>
The S3 storage provider can be configured to change the access and secret keys, the AWS region and the S3 bucket to use. None of these values have any defaults.
- A list of all valid region endpoints can be found here
- If the access and secret keys are omitted then the connection will try using instance authentication. This is useful for managing credentials inside of AWS itself.
<S3StorageProvider> <AccessKey>YOUR_ACCESS_KEY</AccessKey> <SecretKey>YOUR_SECRET_KEY</SecretKey> <RegionEndpoint>ap-southeast-2</RegionEndpoint> <BucketName>MyApplicationBucket</BucketName> </S3StorageProvider>
Was this article helpful?