Open Closed

Change the folder path in azure blob container without "host" folder name. #9652


User avatar
0
imranStem created

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)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    To remove the "host" folder from your Azure Blob Storage path when using ABP's Blob Storing system, you are correct to set IsMultiTenant = false in 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:

    1. Clear Existing Blobs: The "host" folder may persist from previous uploads. Try uploading a new file after applying the configuration change.

    2. Correct Container Configuration: Double-check that the configuration is applied to the correct container and that there are no overrides elsewhere in your codebase.

    3. 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;
            });
        });
    });
    
    1. Restart Application: After making changes, restart your application to ensure the new configuration is loaded.

    2. 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.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can override the DefaultAzureBlobNameCalculator to remove the host

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/DefaultAzureBlobNameCalculator.cs#L6-L21

  • User Avatar
    0
    imranStem created

    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.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    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}";
        }
    }
    
    
  • User Avatar
    0
    imranStem created

    Its still not working. I have checked in host project as well as in application project.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to use [Dependency(ReplaceServices = true)]?

    Please set a breakpoint to see if the Calculate method 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.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 01, 2025, 08:37