Table of Contents

File Management

Introduction

Available only in ASP .NET Core, the file management allows you to upload and download files securely (authenticated).

Prerequisites

  1. Docker
  2. MibConfig via ENVVAR

Required Configuration Files

Some configurations are required by the microservice and for the service that consumes it service.

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)

In both time-related config the time informed must be in seconds.

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.