Configure the File Upload Folder
When building a web application that requires users to upload or download files (documents, images, etc.), file storage can be an important aspect of the application architecture.
Where Should I Store Files?
FintechOS platform supports multiple storage providers for storing the uploaded or generated user files. When building web applications using FintechOS technology, you’ve got a few choices for where to store your files:
The local file system refers to either a local path on the application server or a shared folder on the network containing the application server. While it is the default storage provider, you might be running out of disk space or you might find it a very challenging task to ensure that files are properly backed up and available at all times.
If you’ll be storing large blobs of content, you might want to consider one of the other options. Storing files in a file storage service like Amazon S3 Buckets or Azure Blob is a great option if you’ll be storing large blobs of content. Not only you stay rest assured that your data is replicated and backed up, but they also ensure scalability and high availability.
This section walks you through the steps needed to configure the "UploadEbs" storage provider /location as needed.
There are no special configurations that have to be made in order to use it other than setting the name of the root folder.
To set the name of the root folder, go to the web.config file, open it and to the appSettings node, add the application setting UploadFolder, as described below:
<configuration> ... <appSettings> ... <add key="UploadFolder" value="path_to_root_folder" /> </appSettings> </configuration>
Depending on where the root folder resides, make sure that you properly set the value of the UploadFolder setting:
- subfolder of the application folder: "~/path/to/uploadfolder/";
- local folder on application server, the full path to local folder, like: "c:\path\to\uploadfolder"
- network shared folder: "\\server\path\to\uploadfolder";
If in the web.config file you do not set the UploadFolder setting, it is automatically set to the default value, that is, "~/UploadEBS/".
This feature is available only for local file system storage. It is not available for Azure Blob Storage or Amazon S3 Buckets Storage.
You can automatically group uploaded files into folders based on the last three characters in their file name (excluding the file extension). To do so, add an feature-uploadfolder-autocreate-subfolders key with a value of 1 in the web.config file:
<add key="feature-uploadfolder-autocreate-subfolders" value="1">
This will save each uploaded file in a
-.files\xyz subfolder of the upload folder, where xyz represents the last three characters of the file name. For example, a file called MyDoc_0caf99b6-549d-48f7-8747-5e3eb82753fd.txt will be saved in a folder structure similar to:
...\ UploadEBS\ -.files\ 3fd\ MyDoc_0caf99b6-549d-48f7-8747-5e3eb82753fd.txt
Setting the feature-uploadfolder-autocreate-subfolders key value to 0 disables the feature.
This feature is backward compatible. If a requested file is not stored in the above folder structure, it will be read from the main upload folder or the entity specific upload folder respectively.
To configure FintechOS to store user files in Azure Blob, follow these steps:
- Go to the web.config file and open it.
- Add a
ftosStorageServicesection to the <configSections> element:
- Add a
ftosStorageServicesection (note the AzureBlob type) as child of <configuration> element:
<configuration> <configSections> ... <section name="ftosStorageService" type="EBS.Core.Utils.Services.Config.StorageServiceConfigSection, EBS.Core.Utils"/> </configSections> <configuration>
<configuration> ... <ftosStorageService type="AzureBlob"> <settings> <setting name="connectionString" value="connection_string"/> <setting name="rootContainer" value="root_container"/> </settings> </ftosStorageService> </configuration>
- connectionString is the connection string FintechOS is using to connect to an Azure Blob container;
- rootContainer is the root container name where the user files will be stored.
To enable automatic deployment through ARM templates, the
rootContainer settings must be configured in the <appSettings> element of the web.config file:
<appSettings> ... <add key="ftosStorageService-AzureBlob-connectionString" value="connection_string" /> <add key="ftosStorageService-AzureBlob-rootContainer" value="root_container" /> </appSettings>
Values set in the <appSettings> keys take precedence over the values set in the <ftosStorageService> settings node.
To configure FintechOS to store user files in Amazon S3 Buckets, follow these steps:
- Go to the web.config file and open it.
- To the <configSections> element, add the following two sections: ftosStorageService and aws, as described below:
- Add <ftosStorageService> tag (note the AmazonS3Bucket type) as child of configuration element:
- Add the aws section as child of the configuration element:
<configuration> <configSections> ... <section name="ftosStorageService" type="EBS.Core.Utils.Services.Config.StorageServiceConfigSection, EBS.Core.Utils"/> <section name="aws" type="Amazon.AWSSection, AWSSDK.Core"/> </configSections> <configuration>
<configuration> ... <ftosStorageService type="AmazonS3Bucket"> <settings> <setting name="AWSAccessKey" value="access_key" /> <setting name="AWSSecretKey" value="secret_key" /> <setting name="BucketName" value="bucket_name"/> </settings> </ftosStorageService> </configuration>
AWSSecretKey are used by FTOS to sign the requests made to AWS. For more information, see Access Keys (Access Key ID and Secret Access Key).
BucketName is the root bucket name where the user files will be stored.
<configuration> ... <aws region="aws_region"> </aws> </configuration>
The only required attribute is region. For a complete list of available regions, see Amazon documentation, section Regions, Availability Zones, and Local Zones. The region attribute must have one of the values from the column "Region". E.g.:
For a list of allowed elements in the AWS section, see Configuration Files Reference for AWS SDK for .NET.