Skip to main content

File Storage

File storage, display, and management are common needs in many business applications. Shesha caters to these needs with its built-in file management features. These include:

  1. APIs for the uploading, downloading, deletion, updating (incl. version management) of files
  2. UI components that can bind to entities and allow uploading, downloading and viewing of files
  3. Storage providers that allow files to be stored in various types of storage locations. Currently, local file storage and Azure Blob Storage are supported, with the option for custom providers to be implemented.
  4. Metadata management for all files uploaded

Adding a file to an entity

If you wish to be able to upload a file against an entity, simply add a property of type StoredFile to the entity as follows:

public class MyEntityWithFile : Entity
{
...

public virtual StoredFile MyFile { get; set; }

...
}

On the front-end you can then use the File form component and bind it to your new StoredFile property as illustrated below:

TODO: INSERT SCREENSHOT WITH FILE COMPONENT

Refer for the File form component for more details on how to configure the component.

Adding a list of files to an entity

If you wish to be able to upload a list of files against an entity, no changes are required to your domain model. Simply add the FileList form component to your form and bind it to your entity as illustrated below:

TODO: INSERT SCREENSHOT WITH FILE COMPONENT

The FileList component will automatically track which files are part of the list using the OwnerType, OwnerId and Category properties of the StoredFile entity. Note that the FileList component will only be able to update these properties accurately if properly configured. Refer for the FileList form component for more details on how to configure the component.

Note: In cases where files are upload files before the owner entity has been persisted and therefore assigned an Id, the dynamically generated Create end-point will automatically the update of OwnerType, OwnerId and Category properties for all previously created StoredFile entities created once the owner entity has been persisted and assigned an Id. If you are not using the default Create end-point, you will need to ensure that these properties are updated manually on your custom end-point using the TODO: Ask Ernest for the name of the method method.

StoredFile Entity and File Metadata

The StoredFile entity is used to store metadata about files uploaded into the application and has the following properties:

PropertyTypeDescription
OwnerIdstringThe ID of the owner of the file.
OwnerTypestringThe type of the owner of the file.
FileNamestringThe original name of the file. When saved in the system's storage location the original file name is replaced by a Guid to avoid name clashes. This therefore provides a view of the original name of the file.
FileTypestringTODO: Confirm usage The type of the file.
CategoryInt64?TODO: Confirm usage and if maps to a reference list The category of the file.
DescriptionstringThe description of the file.
SortOrderintThe sort order of the file.
ParentFileStoredFileTODO: Confirm usage The parent file of the current file.
FolderstringThe folder where the file is stored relative to root location of the file storage location.
IsVersionControlledboolIndicates whether the file is version controlled.
TenantIdint?The ID of the tenant.

StoredFileVersion

PropertyTypeDescription
FileStoredFileThe StoredFile this version relates to.
VersionNointThe version number.
FileSizeInt64The size of the file stored in Bytes.
FileNamestringThe name of the file on the storage location. Note this will differ from the original name of the file as it is replaced with a Guid when stored to ensure uniqueness.
FileTypestringThe type of the file as per the file extension of the file when uploaded.
DescriptionstringAn optional description for the file version.
IsSignedboolTODO: Confirm usage
IsLastboolIf true, indicates that this is the latest version for the file.

File management API

[TODO]

Storage of files

Uploaded files are not stored in the database, but rather as separate binary files in a file storage location. Shesha provides for the storage of files in the following types of locations:

  • Local disk
  • Azure Blob Storage

Additional storage locations can be added by implementing the IFileStorageProvider interface.

Local file storage

Uploaded files will be store Local file. To use local file storage update the AppSettings.json as follows

TODO

Azure Blob Storage

Uploaded files will be store Azure Blob Storage. To use Azure Blob Storage: update the configuration AppSettings.json as follows

TODO

See Also