Ends in:
4 DAYS
10 HRS
7 MIN
46 SEC
Ends in:
4 D
10 H
7 M
46 S
Open Closed

Configuring Blob Storing Using File system as the storage provider. #5131


User avatar
0
ed_developer2 created

Hello,

I am trying to change the storage provider from default to file system, for which I am configuring AbpBlobStoringOptions in my HttpApiHost module, And i am storing the path in Abpsettings table and i want to access the path using ISettingProvider, but the problem is I can't Inject ISettingProvider in the constructor because the module requires a parameterless constructor to create the instance. so can you help me with providing a way to retrieve the path from the abpsettings table in my hostmodule.

Thank you.


1 Answer(s)
  • User Avatar
    0
    jfistelmann created

    Hi,

    let me rephrase just to ensure that I understood your issue.

    1. You want to use Blob Storage with the file system provider
    2. Instead of setting a hardcoded base path (like described here https://docs.abp.io/en/abp/latest/Blob-Storing-File-System#configuration) you want to use a value which is determined at runtime

    You can archieve that by implementing your own IBlobFilePathCalculator as described here: https://docs.abp.io/en/abp/latest/Blob-Storing-File-System#file-path-calculation

    An example would look as follows:

    using System.IO;
    using Volo.Abp.BlobStoring;
    using Volo.Abp.BlobStoring.FileSystem;
    using Volo.Abp.Settings;
    
    namespace app;
    
    public class MyBlobFilePathCalculator : IBlobFilePathCalculator
    {
        private readonly ISettingProvider _settingProvider;
    
        public MyBlobFilePathCalculator(ISettingProvider settingProvider)
        {
            _settingProvider = settingProvider;
        }
    
        public string Calculate(BlobProviderArgs args)
        {
            string basePath = _settingProvider.GetOrNullAsync("MySetting").Result;
    
            return Path.Combine(basePath, args.ContainerName, args.BlobName);
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35