Skip to content

Conversation

@aixasz
Copy link

@aixasz aixasz commented Aug 28, 2025

Fixes

Issue #47

Description

Sets Content-Type header on Azure blob uploads based on file extension to ensure proper browser rendering of files (e.g., images display inline instead of downloading).

Implementation:

  • Detects MIME type from blob path using MimeUtility.GetMimeMapping() from the lightweight MimeMapping package
  • Automatically defaults to "application/octet-stream" for unknown extensions (built into MimeMapping library)
  • Sets Content-Type via BlobUploadOptions with BlobHttpHeaders during upload

- Modified WriteAsync to detect MIME type from blob path using _mime.TryGetContentType
- Falls back to "application/octet-stream" when no mapping is found
- Uses BlobUploadOptions with BlobHttpHeaders to ensure Content-Type is stored
- Fixes issue where browsers download images instead of rendering inline
@aixasz aixasz force-pushed the feature/azure-blob-content-type-according-to-file-extension branch from eadbcb7 to 71f044f Compare August 28, 2025 08:25
@robinrodricks
Copy link
Owner

Looks good but can you rewrite it to not use the Microsoft.AspNetCore.StaticFiles package, as that pulls in the entire ASP.net core server set of packages!

robinrodricks and others added 7 commits October 1, 2025 16:43
- Modified WriteAsync to detect MIME type from blob path using _mime.TryGetContentType
- Falls back to "application/octet-stream" when no mapping is found
- Uses BlobUploadOptions with BlobHttpHeaders to ensure Content-Type is stored
- Fixes issue where browsers download images instead of rendering inline
…sion' of https://github.com/aixasz/FluentStorage into feature/azure-blob-content-type-according-to-file-extension
Switched from Microsoft.AspNetCore.StaticFiles to MimeMapping for determining MIME types in AzureBlobStorage. Updated the project dependencies and refactored code to use MimeUtility.GetMimeMapping instead of FileExtensionContentTypeProvider.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants