Open Closed

BlobStoring ContentType #1041


User avatar
0
dean_ve created
  • ABP Framework version: v4.2.2
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

I am using the FileManagement module to store files in Aws S3 using the AwsBlobProvider.

We need to set the correct Content Type (Mime Type) on Aws when the files are stored. The correct content type is stored in the local DB and looking at the code there is a MimeType property on the FileDescriptor object passed to the IFileDescriptorRepository.InsertAsync() method. I've created my own AwsBlobProvider that can accept ContentType but how do I intercept the IFileDescriptorRepository.InsertAsync() to insert the MimeType?

Thanks, Dean


2 Answer(s)
  • User Avatar
    0
    cotur created

    Hi @dean_ve

    The File Management module stores blob and creates it's entity in the FileManager,

    FileManager.cs

    public class FileManager : DomainService, IFileManager
    {
            ....
            protected IBlobContainer<FileManagementContainer> BlobContainer { get; }
            ....
            
            public virtual async Task<FileDescriptor> CreateAsync(
                string name,
                string mimeType,
                byte[] content,
                Guid? directoryId = null,
                Guid? tenantId = null,
                bool overrideExisting = false)
            {
                var fileDescriptor = await SaveFileDescriptorAsync(name, mimeType, content.Length, directoryId, tenantId, overrideExisting);
    
                await BlobContainer.SaveAsync(fileDescriptor.Id.ToString(), content, true);
                
                return fileDescriptor;
            }
    

    As you see at the code, you should override this method.

    But this domain service injects the BlobContainer via interface, as you know, ABP Blob Storing module does not has abstraction that accepts Mime/ContentType for saving blobs.

    So you should create a new YourFileManager that inherits FileManager and replace it with the current.

    Inject your blob provider, and override the CreateAsync method, and use your new injected container to storage your blob with mimetype.

  • User Avatar
    0
    dean_ve created

    Thanks, that helps a lot.

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