dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

[iOS][Maui.Essentials] File.ContentType from MediaPicker is not in MIME format #15562

Open takla21 opened 1 year ago

takla21 commented 1 year ago

Description

Unlike other platforms, ContentType property from the file received after calling MediaPicker.PickPhotoAsync is not in the MIME format.

Actual result p

Expected result Screenshot_20230609-165301

Steps to Reproduce

ezgif com-video-to-gif

Link to public reproduction project repository

https://github.com/takla21/MauiEssentialsContentTypeSample

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 16.4

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.9.0 Preview 1(8.0.3). Repro on iOS 17.0, not repro on Windows 11 and Android 14.0-API34 with below Project: MediaPickerContentType.zip

breyed commented 5 months ago

The summary for FileBase.ContentType is:

Gets or sets the file's content type as a MIME type (e.g.: image/png).

PickPhotoAsync on iOS is failing to include the image/ prefix. If you pick a photo, ContentType is jpeg instead of image/jpeg. If you pick a screenshot, ContentType is png instead of image/png.

dotMorten commented 5 months ago

I'm hitting this too and took a while to figure out why this wasn't working right (also I don't get why MediaPicker.CapturePhotoAsync is returning a PNG in the first place with no way of getting at the original UIImage. That seem very inefficient for photos.

Anyway the bug is most obviously here: https://github.com/dotnet/maui/blob/372c66ce0107599fe2b9f804492d91e3f99a3d1b/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs#L65-L74 It just uses the extension, which isn't a content type. A quick localized fix would be to use the overload that sets the contenttype here: https://github.com/dotnet/maui/blob/372c66ce0107599fe2b9f804492d91e3f99a3d1b/src/Essentials/src/FileSystem/FileSystem.ios.cs#L186

FlavioGoncalves-Cayas commented 3 months ago

Same thing for capturing/picking videos.

MitchBomcanhao commented 5 days ago

I'm hitting this too and took a while to figure out why this wasn't working right (also I don't get why MediaPicker.CapturePhotoAsync is returning a PNG in the first place with no way of getting at the original UIImage. That seem very inefficient for photos.

Anyway the bug is most obviously here:

maui/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs

Lines 65 to 74 in 372c66c

string PlatformGetContentType(string extension) { // ios does not like the extensions extension = extension?.TrimStart('.');

// var id = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension, null); // var mimeTypes = UTType.CopyAllTags(id, UniformTypeIdentifiers.UTTagClass.MimeType.ToString()); // return mimeTypes?.Length > 0 ? mimeTypes[0] : null;

return extension;

It just uses the extension, which isn't a content type. A quick localized fix would be to use the overload that sets the contenttype here: maui/src/Essentials/src/FileSystem/FileSystem.ios.cs

Line 186 in 372c66c

: base()

the PR says that the developer was "still working on it" over 2 years ago. guess they forgot. Pull request comment https://github.com/dotnet/maui/pull/4272/files#r806907016 Image

FlavioGoncalves-Cayas commented 1 day ago

And then the PR just got merged anyways, I guess... @rmarinho @mattleibow