I am using the azure blob storage module and when I upload image on blob, it creates the host name folder on the blob container. I don't want to create the host folder and want to use my path without the host folder. I set multi tenancy false but still it is pointing to host folder.
Here is my configuration in module
var configuration = context.Services.GetConfiguration();
Configure<AbpBlobStoringOptions>(options =>
{
options.Containers.Configure<CategoryBlobContainer>(container =>
{
container.IsMultiTenant = false;
container.UseAzure(azure =>
{
azure.ConnectionString = configuration["BlobStoring:Containers:AzureContainer:Configuration:ConnectionString"];
azure.ContainerName = configuration["BlobStoring:Containers:AzureContainer:Configuration:ContainerName"];
azure.CreateContainerIfNotExists = true;
});
});
});
- Exception message and full stack trace:
- Steps to reproduce the issue:
6 Answer(s)
-
0
To remove the "host" folder from your Azure Blob Storage path when using ABP's Blob Storing system, you are correct to set
IsMultiTenant = falsein your container configuration. This should prevent the framework from prefixing blobs with the tenant or "host" folder. However, if you are still seeing the "host" folder, ensure the following:Clear Existing Blobs: The "host" folder may persist from previous uploads. Try uploading a new file after applying the configuration change.
Correct Container Configuration: Double-check that the configuration is applied to the correct container and that there are no overrides elsewhere in your codebase.
No Custom Path Logic: Ensure you are not programmatically adding the "host" prefix when saving blobs.
Here is the correct configuration:
var configuration = context.Services.GetConfiguration(); Configure<AbpBlobStoringOptions>(options => { options.Containers.Configure<CategoryBlobContainer>(container => { container.IsMultiTenant = false; // This disables the "host" or tenant folder container.UseAzure(azure => { azure.ConnectionString = configuration["BlobStoring:Containers:AzureContainer:Configuration:ConnectionString"]; azure.ContainerName = configuration["BlobStoring:Containers:AzureContainer:Configuration:ContainerName"]; azure.CreateContainerIfNotExists = true; }); }); });Restart Application: After making changes, restart your application to ensure the new configuration is loaded.
Blob Path on Save: When saving blobs, use only the file name or your desired path, not a path prefixed with "host".
Example:
await _blobContainer.SaveAsync("my-image.jpg", fileStream);If you follow these steps and still see the "host" folder, ensure that:
- The correct container type is used in your service.
- There are no other modules or custom code re-enabling multi-tenancy for this container.
For more details, see the official documentation:
If the issue persists after these checks, please verify that your application is not running in a multi-tenant context elsewhere, and that the container configuration is not being overridden in another module.
Sources:
- https://docs.abp.io/en/abp/latest/Blob-Storing
- https://docs.abp.io/en/abp/latest/Blob-Storing-Azure
- https://abp.io/docs/latest/framework/infrastructure/blob-storing/
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
hi
You can override the
DefaultAzureBlobNameCalculatorto remove thehosthttps://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/DefaultAzureBlobNameCalculator.cs#L6-L21
-
0
I have created the class but do I need to register this class in configuration? How it will overwrite the existing class? I am using abp azure module nuget package so Do I need to use the source code instead of package.
-
0
hi
Add this class to your solution.
Thanks.
using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring.Azure; using Volo.Abp.DependencyInjection; using Volo.Abp.MultiTenancy; namespace MyCompanyName.MyProjectName.Web; [Dependency(ReplaceServices = true)]` [ExposeServices(typeof(IAzureBlobNameCalculator), typeof(DefaultAzureBlobNameCalculator))] public class MyAzureBlobNameCalculator : DefaultAzureBlobNameCalculator { public MyAzureBlobNameCalculator(ICurrentTenant currentTenant) : base(currentTenant) { } public override string Calculate(BlobProviderArgs args) { return CurrentTenant.Id == null ? $"{args.BlobName}" : $"tenants/{CurrentTenant.Id.Value:D}/{args.BlobName}"; } } -
0
Its still not working. I have checked in host project as well as in application project.
-
0
hi
Can you try to use
[Dependency(ReplaceServices = true)]?Please set a breakpoint to see if the
Calculatemethod has been called.[Dependency(ReplaceServices = true)] [ExposeServices(typeof(IAzureBlobNameCalculator), typeof(DefaultAzureBlobNameCalculator))] public class MyAzureBlobNameCalculator : DefaultAzureBlobNameCalculator { public MyAzureBlobNameCalculator(ICurrentTenant currentTenant) : base(currentTenant) { } public override string Calculate(BlobProviderArgs args) { return CurrentTenant.Id == null ? $"{args.BlobName}" : $"tenants/{CurrentTenant.Id.Value:D}/{args.BlobName}"; } }Thanks.