3.2 KiB
//[doc-seo]
{
"Description": "Learn how to store BLOBs in a microservice solution using ABP Framework, including database integration for efficient large object management."
}
Microservice Solution: BLOB Storing
//[doc-nav]
{
"Next": {
"Name": "CORS configuration in the Microservice solution",
"Path": "solution-templates/microservice/cors-configuration"
}
}
You must have an ABP Business or a higher license to be able to create a microservice solution.
This document explains how to store BLOBs (Binary Large Objects) in a microservice solution. It is common to store files, images, videos, and other large objects in a distributed system. You can learn more about BLOB storage in the BLOB Storing System documentation.
In the microservice solution template, the Database Provider is used to store BLOBs in the database. The Volo.Abp.BlobStoring.Database.EntityFrameworkCore or Volo.Abp.BlobStoring.Database.MongoDB package provides the necessary implementations to store and retrieve BLOBs in the database. This setup is integrated into the microservice solution template and is used in all related projects. You can change the database configuration in the appsettings.json file of the related project. The default configuration is for SQL Server as follows:
"AbpBlobStoring": "Server=localhost,1434; User Id=sa; Password=myPassw@rd; Database=MyProjectName_BlobStoring; TrustServerCertificate=true"
Provider Selection
The Database Provider is selected by default. In ABP Studio, use the BLOB Storing step to keep database storage, configure the File System Provider, or choose manual configuration for another provider. In the CLI, pass --blob-storage database, --blob-storage file-system, or --blob-storage manual. When using file-system storage, pass --blob-storage-path <path> to set the base path; otherwise, ./BlobStoring is used.
If you choose manual configuration, configure your preferred provider before using BLOB storage. See the BLOB Storing provider documentation for the available providers and their setup requirements.
Afterwards, you can use the IBlobContainer or IBlobContainer<T> service to store and retrieve BLOBs. Here is an example of storing a BLOB:
public class MyService : ITransientDependency
{
private readonly IBlobContainer _blobContainer;
public MyService(IBlobContainer blobContainer)
{
_blobContainer = blobContainer;
}
public async Task SaveBytesAsync(byte[] bytes)
{
await _blobContainer.SaveAsync("my-blob-1", bytes);
}
public async Task<byte[]> GetBytesAsync()
{
return await _blobContainer.GetAllBytesOrNullAsync("my-blob-1");
}
}
The File Management module is optional and can be added to the solution during the creation process. It provides a user interface to manage folders and files. You can learn more about the module in the File Management document.
