Open Closed

FileManagement AzureBlob possible way how to owerwrite blobname from GUID to normal filename #2134


User avatar
0
cleverplatform created

when I use FileManagement module with Azure Blob storage I want to access to stored file in public container (images for reuse in eCommerce).

on Azure Blob in public container I see only blob guid url "https://xxxxx.blob.core.windows.net/images/host/a726787c-35b9-d554-eef0-3a00377a3195" and "application/octet-stream" content-type.

Is there any way how to overwrite it in application service to store instead Blob GUID, the filename with extension and correct content-type like: "https://xxxxx.blob.core.windows.net/images/host/image123.jpg" ?

thanks Erik

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v4.4.4
  • UI type: MVC
  • DB provider: EF Core
  • **Tiered (MVC) **: yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

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

    Hi,

    This is designed to prevent uploading files with the same name from being overwritten, we store the real file name in the database, it will use the real name when you use the file management module to download files.

    We do not recommend that you use real names to store files in azure blob.

    However, you can do it if you need:

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IFileManager))]
    public class MyFileManager : FileManager
    {
        public MyFileManager(IFileDescriptorRepository fileDescriptorRepository, IBlobContainer<FileManagementContainer> blobContainer, IDirectoryDescriptorRepository directoryDescriptorRepository) : base(fileDescriptorRepository, blobContainer, directoryDescriptorRepository)
        {
        }
    
        public override async Task<FileDescriptor> CreateAsync(string name, string mimeType, IRemoteStreamContent content, Guid? directoryId = null,
            Guid? tenantId = null, bool overrideExisting = false)
        {
            var fileDescriptor = await SaveFileDescriptorAsync(name, mimeType, (int)(content.ContentLength ?? 0), directoryId, tenantId, overrideExisting);
    
            await BlobContainer.SaveAsync(name, content.GetStream(), true);
    
            return fileDescriptor;
        }
    }
    
  • User Avatar
    0
    cleverplatform created

    Thanks a lot - it works perfectly for me. Erik

Made with ❤️ on ABP v9.1.0-preview. Updated on November 19, 2024, 12:56