The Nomirun SDK
provides built-in support for multiple file storage providers, including Azure Blob Storage
, FTP servers
, Amazon S3
, and MinIO
. This enables flexible and consistent file handling across different storage backends.
To use a storage provider, simply register it in your application and inject IStorageService<FileObject>
where needed. This service is registered with a transient
lifetime and gives you access to a unified interface for working with files.
The IStorageService<FileObject>
interface includes a set of standard methods implemented across all supported providers, allowing you to switch between storage backends with minimal code changes.
public interface IStorageService<TInput>
{
Task<bool> UploadFile(TInput file);
Task<bool> UploadFiles(List<TInput> files);
Task<byte[]> DownloadFile(TInput file);
Task<bool> DeleteFile(TInput file);
Task<bool> DeleteFiles(IEnumerable<TInput> files);
Task<bool> FileExists(TInput file);
}
services.ConfigureAzureStorageService(options =>
{
options.ConnectionString = configuration["AzureStorage:ConnectionString"];
});
services.ConfigureFtpStorageService(options =>
{
options.Server = configuration["FtpStorage:Server"];
options.Port = configuration.GetValue<short>("FtpStorage:Port");
options.Username = configuration["FtpStorage:Username"];
options.Password = configuration["FtpStorage:Password"];
options.Ftps = configuration.GetValue<bool>("FtpStorage:Ftps");
});
services.ConfigureAmazonS3Service(options =>
{
options.AccessKey = configuration["AmazonS3Storage:AccessKey"];
options.SecretKey = configuration["AmazonS3Storage:SecretKey"];
options.Bucket = configuration["AmazonS3Storage:Bucket"];
options.Region = configuration["AmazonS3Storage:Region"];
});
services.ConfigureMinioService(options =>
{
options.AccessKey = configuration["MinioStorage:AccessKey"];
options.SecretKey = configuration["MinioStorage:SecretKey"];
options.Bucket = configuration["MinioStorage:Bucket"];
options.Endpoint = configuration["MinioStorage:Endpoint"];
options.UseSsl = configuration.GetValue<bool>("MinioStorage:UseSsl");
options.Region = configuration["MinioStorage:Region"];
});
Then you can inject IStorageService<FileObject>
in your code like this:
public class CustomerFilesController : ControllerBase
{
private readonly ILogger<CustomerFilesController> _logger;
private readonly IStorageService<FileObject> _storageService;
public CustomerFilesController(ILogger<CustomerFilesController> logger,
IStorageService<FileObject> storageService)
{
_logger = logger;
_storageService = storageService;
}
[HttpPost("files")]
public async Task<IActionResult> UploadFile(IFormFile file)
{
await using (var fileStream = new MemoryStream())
{
await file.CopyToAsync(fileStream);
var uploaded = await _storageService.UploadFile(new FileObject
{
Container = "mycontainer",
RemotePath = "/products/guitar.xlsx",
FileContent = fileStream.ToArray()
});
return Ok(uploaded);
}
}
}