Skip to content

Conversation

devanathan-vaithiyanathan
Copy link
Contributor

@devanathan-vaithiyanathan devanathan-vaithiyanathan commented Oct 8, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details

On Windows, the StorageFile.ContentType API often returns a generic or incorrect MIME type (e.g., .webp → application/octet-stream), causing FilePicker to report wrong or empty ContentType values.

Description of Change

Fixed by adding an extension-to-MIME mapping dictionary in FileSystem.uwp.cs that includes .webp and other formats. The solution uses fallback logic - it preserves Windows' native ContentType when correct, but automatically uses our mapping when Windows returns the generic "application/octet-stream" or empty values.

Issues Fixed

Fixes #31808

Tested the behavior in the following platforms.

  • Windows
  • Mac

Output Screenshot

Before After
Windows
Before-fix.mp4
Windows
After-fix.mp4

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Oct 8, 2025
Copy link
Contributor

Hey there @@devanathan-vaithiyanathan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Oct 8, 2025
{ ".htm", "text/html" },
{ ".css", "text/css" },
{ ".js", "application/javascript" },
{ ".json", "application/json" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartyIX , Thanks for suggestion, I've modified the changes

{
// Static mapping for file extensions to MIME types
// Used as fallback when Windows StorageFile.ContentType doesn't provide correct MIME type
static readonly Dictionary<string, string> ExtensionToMimeTypeMap = new(StringComparer.OrdinalIgnoreCase)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, use as fallback and only for reading, for faster lookups can use a FrozenDictionary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , Thanks for the suggestion. I have updated the implementation to use FrozenDictionary for faster read-only lookups instead of a regular Dictionary.


#if WINDOWS
[Fact]
public async Task EnsureFileResultContentType()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test correctly PlatformGetContentType, could include more tests?

  • Trailing Spaces: ".jpg "
  • Case Variations: ".JPG", ".Jpg", ".jPg"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , Good point! I have added additional test cases to cover trailing spaces and case-insensitive extensions to ensure PlatformGetContentType handles these scenarios correctly.

if (string.IsNullOrWhiteSpace(extension))
return null;

extension = extension.ToLowerInvariant();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not common, but would require changes to correctly manage multiple dots. Example: .tar.gz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've included a test case for multi-dot extensions like .tar.gz and adjust the logic if necessary to ensure proper content type resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAUI: Windows: FilePicker: Returns wrong ContentType for *.webp files: Returns app/octet-stream.

3 participants