Open takla21 opened 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.
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
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
.
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
Same thing for capturing/picking videos.
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
And then the PR just got merged anyways, I guess... @rmarinho @mattleibow
Description
Unlike other platforms,
ContentType
property from the file received after callingMediaPicker.PickPhotoAsync
is not in the MIME format.Actual result
Expected result
Steps to Reproduce
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