File Management
Introduction
Available only in ASP .NET Core, the file management allows you to upload and download files securely (authenticated).
Grounded against
origin/releases/7.0(MibMicroServices/FileManagement/…,MibServerApi); the cited service/config surfaces are byte-identical onreleases/6.0.
Related docs. File / image / video upload — the asset pipeline — the content-field angle: how an
AdmFieldType.Imagefield, the BFF, and this microservice combine to upload/serve an asset, plus MibServerApi's own duplicated storage config (the sync gotcha).
How it works
File bytes do not travel through the BFF's or the Data API's content save — they go to this microservice, which writes them into a configured StorageArea and returns links that get bound to the content item.
- Authentication. Every request needs a Bearer token (
Authorization: Bearer <token>), validated against MibAuthorization via the injectedIMibAuthorizationClient(Program.cs,Authorization/MibAuthorizationClient.cs).ApiClientId/OauthClientIdidentify the service to MibAuthorization; user data and permissions are cached forUserCacheTime/PermissionCacheTime. - StorageArea. A file lands in a StorageArea (
disk/amazon/azure/smb), selected byStorageAreaId; when null the service picks one via BestServer (first active cloud/UNC area, else the local disk with the most free space). The chosenStorageAreaIdis persisted on the file'sEntityFileLink/LocalFileLink, so moving an asset between areas is a data migration. Storage backends are provided by the sharedMibStorageLib2library. - Upload lifecycle (resumable). start → write bytes (chunked) → check → finalize/bind:
POST upload→PUT upload/content/{guid}/{filename}(withContent-Range, optionalContent-MD5whenForceCheckMd5OnUploadComplete=true) →PUT upload/check→PUT upload/content/{mediatype}/{contentId}(binds the stored file to the content asLocalFileLink[]). A one-shotPOST upload/content/{filename}covers the simple, non-chunked case. - Serving.
GET download/file/...streams the bytes back. For the disk backend, the CMS image preview is not served by this microservice directly — MibServerApi builds the public URL from its ownMibMediaConfig+ a reverse-proxy virtual directory (see file-upload.md#mibserverapi-storage-config).
API Routes
Base routes api/v1 (and api/v2 for the v2 download); all require a Bearer token. Interactive
Swagger/OpenAPI is served at /help once deployed.
| Route | Verb | Purpose |
|---|---|---|
api/v1/upload |
POST | Start a resumable upload → file ids + upload urls. |
api/v1/upload/content/{guid}/{filename} |
PUT | Write bytes (chunked: Content-Range, optional Content-MD5) → 201/206. |
api/v1/upload/check |
PUT | Is the upload complete? |
api/v1/upload/{uploadId}/{filename}/complete |
POST | Mark a resumable upload complete. |
api/v1/upload/content/{mediatype}/{contentId} |
PUT | Finalize → bind LocalFileLink[] to the content item. |
api/v1/upload/content/{filename} |
POST | Simple one-shot upload → default StorageArea. |
api/v1/download/file/{fileName} |
GET | Download a file (also a structured .../{mediaType}/{storageId}/{originalFileName}/{relativeUrl} variant). |
api/v2/download/file/{fileName} |
GET | v2 download (stream). |
api/v1/storagearea/{mediaType}[/{storageAreaId}] |
GET | Resolve StorageArea metadata for a media type (.../full/... returns full storage info). |
Prerequisites
- Docker
- MibConfig via ENVVAR
Required Configuration Files
Configuration is split across the three services that participate. The full key reference for each block is in the sections below; this is which service needs what:
| Config | Cms.MicroService (FileManagement) |
Cms.FrontEnd (MibServer3/BFF) |
Cms.Api (MibServerApi) |
|---|---|---|---|
MibFileManagementMicroServiceServerConfig |
✅ | ||
MibFileManagementMicroServiceClientConfig |
✅ | ✅ | |
MibServerMediaConfig (storageArea<N>) |
✅ | ✅ (own copy) | |
MibMediaConfig (public base URL) |
✅ | ||
MibStorageLib2Config (default/temp backend) |
✅ | ||
Storage creds MibAwsConfig/MibAzureConfig/MibSmbConfig |
✅ | ✅ (same values) | |
MibCacheConfig, MibLogConfig |
✅ |
Important
MibServerApi is not a pure client. Besides the client config, it keeps its own copy of
MibServerMediaConfig, its own MibMediaConfig (for the served URL), and the storage credentials —
and for some read paths it talks to the storage backend directly. These must be kept in sync with the
microservice by hand. See the full gotcha + a change checklist in
file-upload.md#mibserverapi-storage-config.
Server Side Configurations
MibFileManagementMicroServiceServerConfig
- MibAuthUrl: MibAuthorization service access url.
- ApiClientId: ApiClient id to obtain permissions in MibAuthorization.
- OauthClientId: OauthClient id to obtain permissions in MibAuthorization.
- UserCacheTime: Maximum time to cache user data. (default = 0)
- PermissionCacheTime: Maximum time to cache user permissions. (default = 0)
- ImageFileExtensions: List of file extensions classified as images. Through this information, the microservice can identify whether the file contained in the upload is an image. (default is empty)
- ForceCheckMd5OnUploadComplete: If true, requires validation of the MD5 hash of files at the end of the upload process. (default = false)
For more information, see all settings here.
MibPermissionMicroServiceClientConfig
- UrlMicroService
MibAwsConfig
- AccessKey
- SecretKey
- UrlExpirationTime
- RegionEndpoint
MibAzureConfig
- AccessName
- AccessKey
- UrlExpirationTime
MibCacheConfig
Defines general configurations for caching. Please refer to MibCacheConfig for complete list of configuration keys.
MibLogConfig
Defines general configurations for logging. Please refer to MibLogConfig for complete list of configuration keys.
MibMediaConfig
- IsAwsStorage
- IsAzureStorage
Configurations must be carried out by creating identifiers for each item. example:
MibMediaConfig_StorageArea0_IsAwsStorage=true
MibMediaConfig_StorageArea0_IsAzureStorage=true
MibMediaConfig_StorageArea0_default=http://localhost.com.br
MibMediaConfig_StorageArea1_IsAwsStorage=false
MibMediaConfig_StorageArea1_IsAzureStorage=false
MibMediaConfig_StorageArea1_default=http://localhost.com.br
MibMediaConfig_StorageArea2_IsAwsStorage=false
MibMediaConfig_StorageArea2_IsAzureStorage=false
MibMediaConfig_StorageArea2_IMAGES=http://localhost.com.br
MibServerMediaConfig
- Active
- Path
- StorageType
azure, amazon, smb, disk, ftp, dropbox, sshaccess - IsAzurePublic
- IsAwsPublic
- SubFolder
- AwsRegion
Configurations must be carried out by creating identifiers for each item. example:
MibServerMediaConfig_StorageArea0_Active=true
MibServerMediaConfig_StorageArea0_Path=../prod
MibServerMediaConfig_StorageArea0_StorageType=disk
MibServerMediaConfig_StorageArea0_IsAzurePublic=false
MibServerMediaConfig_StorageArea0_IsAwsPublic=false
MibServerMediaConfig_StorageArea0_SubFolder=
MibServerMediaConfig_StorageArea0_AwsRegion=
MibServerMediaConfig_Temp_Active=true
MibServerMediaConfig_Temp_Path=../temp
MibServerMediaConfig_Temp_StorageType=disk
MibSmbConfig
- Domain
- Username
- Password
MibStorageLib2Config
- Type
azure, amazon, smb, disk, ftp, dropbox, sshaccess
According to the configured type, the configuration data is different. Look:
MibStorageLib2Config_Azure_AccountName=
MibStorageLib2Config_Azure_AccountKey=
MibStorageLib2Config_Azure_Bucket=
MibStorageLib2Config_Azure_UseHttps=
MibStorageLib2Config_Azure_MultpartUploadMinsize=
MibStorageLib2Config_Azure_ParallelThreadCount=
MibStorageLib2Config_Amazon_AccessKey=
MibStorageLib2Config_Amazon_SecretKey=
MibStorageLib2Config_Amazon_Bucket=
MibStorageLib2Config_Amazon_UseHttps=
MibStorageLib2Config_Amazon_MaxFilesList=
MibStorageLib2Config_Amazon_UploadTimeout=
MibStorageLib2Config_Amazon_RegionEndpoint=
MibStorageLib2Config_Amazon_MultipartUploadMinSize=
MibStorageLib2Config_Amazon_UseReducedRedundancy=
MibStorageLib2Config_Smb_Server=
MibStorageLib2Config_Smb_Path=
MibStorageLib2Config_Smb_Username=
MibStorageLib2Config_Smb_Password=
MibStorageLib2Config_Smb_Domain=
MibStorageLib2Config_Smb_BlockSize=
MibStorageLib2Config_Smb_ForceMultiplatformSmbStorage=
MibStorageLib2Config_Disk_Path=
MibStorageLib2Config_Disk_BlockSize=
MibStorageLib2Config_Ftp_Server=
MibStorageLib2Config_Ftp_Port=
MibStorageLib2Config_Ftp_Path=
MibStorageLib2Config_Ftp_Username=
MibStorageLib2Config_Ftp_Password=
MibStorageLib2Config_Ftp_WaitTime=
MibStorageLib2Config_Ftp_UsePassiveMode=
MibStorageLib2Config_Ftp_UseSsl=
MibStorageLib2Config_Dropbox_Token=
MibStorageLib2Config_Dropbox_MultipartUploadMinSize=
MibStorageLib2Config_SshAccess_Server=
MibStorageLib2Config_SshAccess_Username=
MibStorageLib2Config_SshAccess_Password=
MibStorageLib2Config_SshAccess_Port=
MibStorageLib2Config_SshAccess_KeyFilePath=
MibStorageLib2Config_SshAccess_StorageRootPath=
Simplified upload and download routes
This service provides a simplified upload/download route. These are:
- /api/v1/upload/content/{filename}
- /api/v1/download/file/{fileName}
For theses routes, MibStorageLib2Config_Default_Type is used to determinate the storage used for persistance (upload) and file recovery (download).
Some examples:
Configured to use disk storage
MibStorageLib2Config_Default_Type=disk
MibStorageLib2Config_Disk_Path=./app/storage
Important
When using File Management Service with disk storage type, the image preview functionality in the CMS requires the storage volume from the File Management Service to be mapped to a virtual directory through a reverse proxy server. The URL of this virtual directory must be specified in MibApi in the configuration MIBMEDIACONFIG_STORAGEAREA(?)_DEFAULT, which will then aggregate metadata and build the final image's url.
The example below illustrates a scenario where the route /storage has been set up in our reverse proxy server to be a virtual directory that maps to the docker volume where File Management Service has been configured to store the medias when using disk storage type.
(Mib Api Configurations)
MIBMEDIACONFIG_STORAGEAREA1_DEFAULT=https://qa50.mediaibox.com.br/storage/filemanagement
MIBMEDIACONFIG_STORAGEAREA1_STORAGETYPE=disk
Configured to use amazon storage
MibStorageLib2Config_Default_Type=amazon
MibStorageLib2Config_Amazon_AccessKey=myAccessKey
MibStorageLib2Config_Amazon_SecretKey=mySecretKey
MibStorageLib2Config_Amazon_Bucket=muBucket
Client Side Configurations
MibFileManagementMicroServiceClientConfig
- UrlMicroService: MibFileManagement service access url.
- MaxRetries: The maximum number of retry attempts before considering the associated operation to have failed.
- RetryInterval: Interval until the next retry. (in seconds)
Important
Mib Server Api is still dependent on some configurations such as MibServerMediaConfig, MibMediaConfig, MibStorageLib2Config in order to communicate appropriately with Mib File Management Service. We intend to address this in a future release.
In the meanwhile we ask you to reapply the configs/env from the Mib File Management Service also in the Mib Server Api.
Solutions that make use of the File Management Service
How to use the File Management Service?
Firstly, any request for FileManagement requires a token for authentication. This token must be stated in the header Authorization followed by the value Bearer my_token. The token will be validated in the MibAuthorization service.
There are two ways to consume the service:
NugetPack
Two nugets packages are avaliable for using the service. Are they:
- MediaiBox.Cms.MicroServices.FileManagement.Client
- MediaiBox.Cms.MicroServices.FileManagement.Model
All methods in FileManagement.Client are documented.
API
It's possible to access the API documentation, after the service is deployed, through the url /help. Swagger documentation will be displayed with a description of the functionality of each of the methods.