Developer Docs

Using the File Storage Provider (C#Bot)

Introduction

When using the file or 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:

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 FILE_SYSTEM and 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>

S3 Configuration

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.

Notes:

<S3StorageProvider>
    <AccessKey>YOUR_ACCESS_KEY</AccessKey>
    <SecretKey>YOUR_SECRET_KEY</SecretKey>
    <RegionEndpoint>ap-southeast-2</RegionEndpoint>
    <BucketName>MyApplicationBucket</BucketName>
</S3StorageProvider>

Was this article helpful?

Thanks for your feedback!

If you would like to tell us more, please click on the link below to send us a message with more details.

Tool:

Generate

Iterate

Bot:

C#Bot

SpringBot

On this page

New to Codebots?

We know our software can be complicated, so we are always happy to have a chat if you have any questions.