Skip to content

Backend File Manager

The purpose for this service is to upload/download files to/from FileStorage from a backend service.

In order to use the File Manager we need to reference the FileManagerClient project:

XML
<ProjectReference Include="$(ServicesPath)FileStorage/ITsynch.Suite.FileStorage.FileManagerClient/ITsynch.Suite.FileStorage.FileManagerClient.csproj" />

And add the dependency in the application module:

C#
1
2
3
4
5
6
public override void SetupModule(IModuleBuilder builder)
{
    base.SetupModule(builder);

    builder.DependsOn<FileManagerClientModule>();
}

Also, we need to configure the Service Discovery module, for this we need to add the following options to our appsettings.json:

JSON
1
2
3
4
5
{
    "ServiceDiscoveryModuleOptions": {
        "EnforceSecureChannels": false
    }
}

Now we are ready to inject the IFileManager interface to our services and we can use the following methods:

  1. Upload: Uploads a single file asynchronously and returns its Guid when the upload is fully completed.
  2. UploadMultiple: Uploads a list of files asynchronously and returns a list of Guids when all uploads are fully completed.
  3. Download: Returns an asynchronous FileStream for a given file Correlation Id.
  4. UploadTemporalFile: Works the same way that the normal Upload but adds a metadata value that make the file "temporal". This means that the File will be stored in other folder and won't be replicated. Also the lifetime of the file should be shorter than a normal file. A use case example is an attachment of an email.
  5. UploadMultipleTemporal: The upload multiple counterpart for temporal files.
  6. DownloadTemporalFile: The download counterpart for temporal files.
  7. DeleteFile: Publishes a message to delete a file physically. This method could be used when doing a rollback for compensating a Saga.

Local testing

If you want to test this running FileStorage in your IDE (or exposing the port 22005 of the pod/container), we need to add one more entry to our appsettings.json:

JSON
{
    "ServiceDiscoveryDefaultProviderOptions": {
        "services": {
            "file-storage-endpoint": {
                "addresses": [ "localhost:22005/files" ]
            }
        }
    },
      "ServiceDiscoveryModuleOptions": {
        "EnforceSecureChannels": false
    },
}

Note

This last configuration is done in docker.host.config.json for the dev environment.