Open Closed

[Minio] About dynamic blob storage container naming #741


User avatar
0
yilmaz.atalar created
  • ABP Framework version: v4.0

Hi,

I want to create buckets dynamically at runtime (and named blob containers also) depends on incoming data (for example I want to store data with daily bucket names. If a record is created on 29-12-2020, my bucket name should be bucket-29-12-2020). But Abp supports blob container configuration while configuring services at startup. How can I achieve this functionality ?

Thanks for your help.


6 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can customize the implementation of IBlobNamingNormalizer:

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IBlobNamingNormalizer))]
    public class MyMinioBlobNamingNormalizer : MinioBlobNamingNormalizer
    {
        public override string NormalizeContainerName(string containerName)
        {
            containerName = base.NormalizeContainerName(containerName);
    
            return containerName.Replace("{date}", DateTime.Now.ToShortDateString());
        }
    }
    

    Your container:

    [BlobContainerName("bucket-{date}")]
    public class DayRollingContainer
    {
    
    }
    
  • User Avatar
    0
    yilmaz.atalar created

    Thanks for your attention.

    @liangshiwei, your approach should work but there is one missing point for my case. Date parameter may not be today. I need to set it explicitly at runtime.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can change it according to your needs, for example, read a date from the settings.

  • User Avatar
    0
    yilmaz.atalar created

    Hi,

    I do not need to set it from a setting or a constant value. I want to set it according to a property of an entity. It is dynamic and changes on every user request to the application service. For example;

    SaveBlob(1) -> Find record with id -> Read creation date -> 2020-01-05 -> Save blob to bucket "bucket-2020-01-05" SaveBlob(35) -> Find record with id -> Read creation date -> 2010-11-22 -> Save blob to bucket "bucket-2010-11-22"

  • User Avatar
    0
    yilmaz.atalar created

    Hi,

    I've achieved this by overriding MinioBlobNameCalculator, MinioBlobProvider and BlobContainerFactory. It should not be that hard. I think abp should support this functionality with an easy way.

    Also, I think GetContainerName function of MinioBlobProvider has a bug. Configuration does not allow empty or null bucket names but that function checks for that and never uses true condition of comparison.

    // always false because empty or null values are not allowed, application throws exception while starting up return configuration.BucketName.IsNullOrWhiteSpace() ? args.ContainerName : configuration.BucketName;

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You are right, We will fix it. thanks.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 17, 2025, 10:38