Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
takla21 opened this issue Jun 9, 2023 · 7 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@takla21
Copy link

takla21 commented Jun 9, 2023

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

  • Deploy sample on iOS
  • Click on the button (to open image gallery)
  • Pick any picture

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

@takla21 takla21 added the t/bug Something isn't working label Jun 9, 2023
@Eilon Eilon added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Jun 9, 2023
@PureWeen PureWeen added this to the Backlog milestone Jun 13, 2023
@ghost
Copy link

ghost commented Jun 13, 2023

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 XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Nov 24, 2023
@XamlTest
Copy link

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
Copy link
Contributor

breyed commented Jun 8, 2024

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
Copy link
Contributor

dotMorten commented Jun 27, 2024

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:

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:

dotMorten added a commit to Esri/arcgis-maps-sdk-dotnet-toolkit that referenced this issue Jun 27, 2024
@FlavioGoncalves-Cayas
Copy link

Same thing for capturing/picking videos.

@MitchBomcanhao
Copy link

MitchBomcanhao commented Nov 22, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants