Skip to content

Comments

[iOS] Fix for the File.ContentType from MediaPicker not being in valid MIME format#28842

Merged
PureWeen merged 4 commits intodotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-15562
Apr 11, 2025
Merged

[iOS] Fix for the File.ContentType from MediaPicker not being in valid MIME format#28842
PureWeen merged 4 commits intodotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-15562

Conversation

@SyedAbdulAzeemSF4852
Copy link
Contributor

@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 commented Apr 8, 2025

Issue Details

  • ContentType property from the file received after calling MediaPicker.PickPhotoAsync is not in the MIME format.

Root Cause

  • Mapping the file extension to a MIME type is not done. The PlatformGetContentType method currently just returns the extension.

Description of Change

  • UTType is only supported starting with iOS 14.0. Therefore If the application is running on iOS 14 or later, retrieved the Uniform Type Identifier (UTI) for a given file extension and obtained the associated PreferredMIMEType property of the Uniform Type Identifier. If a valid MIME type is found, assigned the MIME type to the file extension. Otherwise, returned the original file extension.
  • src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs: Modified the PlatformGetContentType method to use UniformTypeIdentifiers.UTType.GetType for better MIME type resolution.

Validated the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Issues Fixed

Fixes #15562

Output

Before After
Before.mov
After.mov

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

Hey there @@SyedAbdulAzeemSF4852! 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 Apr 8, 2025
@FlavioGoncalves-Cayas
Copy link

Stumbled upon this issue and now this PR once again and wanted to adapt this solution myself.

I noticed that UTType is only supported starting with iOS 14.0. So this solution would crash on iOS versions <14.0.
AFAIK MAUI supports minimum iOS version of 12.2.

@rmarinho rmarinho added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Apr 9, 2025
@jfversluis
Copy link
Member

@SyedAbdulAzeemSF4852 why is this still a draft?

@jfversluis jfversluis requested a review from Copilot April 10, 2025 19:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/Essentials/test/DeviceTests/Tests/FileSystem_Tests.cs:57

  • [nitpick] Consider wrapping the file deletion in a try-finally block to ensure the temporary file is always removed even if an assertion fails.
File.Delete(filePath);

@jfversluis jfversluis added this to the .NET 9 SR7 milestone Apr 10, 2025
@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 marked this pull request as ready for review April 11, 2025 12:59
@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 requested a review from a team as a code owner April 11, 2025 12:59
@PureWeen PureWeen changed the base branch from main to inflight/current April 11, 2025 15:41
@PureWeen PureWeen merged commit f709bc7 into dotnet:inflight/current Apr 11, 2025
3 checks passed
PureWeen pushed a commit that referenced this pull request Apr 16, 2025
…d MIME format (#28842)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format ).

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format )
sheiksyedm pushed a commit to sheiksyedm/maui that referenced this pull request Apr 17, 2025
…d MIME format (dotnet#28842)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format ).

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format )
NanthiniMahalingam pushed a commit to NanthiniMahalingam/maui that referenced this pull request Apr 17, 2025
…d MIME format (dotnet#28842)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format ).

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format )
github-actions bot pushed a commit that referenced this pull request Apr 18, 2025
…d MIME format (#28842)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format ).

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 (File.ContentType from MediaPicker is not in MIME format)

* [iOS] Fix for 15562 ( File.ContentType from MediaPicker is not in MIME format )
PureWeen added a commit that referenced this pull request Apr 23, 2025
### Description of Change

## .NET MAUI Release Notes - Inflight/Candidate

## What's Changed

### MAUI Product Fixes
* Fix CarouselView layout SR6 regressions by @albyrock87 in
#29035
* Revert "[Android] picker - focus/unfocus events (#28122)" by @PureWeen
in https://github.com/dotnet/maui/pull/1fb5164929
* [Windows] Fixed the flyout content width not being set correctly after
updating to WinUI SDK 1.7 by @Tamilarasan-Paranthaman in
#28996
* [Android] picker - focus/unfocus events by @kubaflo in
#28122
* [XC] add IRootObjectProvider by @StephaneDelcroix in
#28310
* [iOS] Fix for the File.ContentType from MediaPicker not being in valid
MIME format by @SyedAbdulAzeemSF4852 in
#28842
* [Android] Fixed the Incorrect Text Color Applied to Selected Tab in
TabbedPage by @Ahamed-Ali in #28844
* [iOS] Fix FlyoutPage does not respond to changes in the
FlyoutLayoutBehavior property by @devanathan-vaithiyanathan in
#28884
* [Android] Fixed ScalingCanvas.SetBlur not working by
@NirmalKumarYuvaraj in #28911
* [iOS] - Resolved Proper Rendering of Dynamic Header/Footer Updates in
CV2 by @prakashKannanSf3972 in #28641
* [iOS] Fixed the TargetInvocationException Occurs When Selecting
Header/Footer After Changing ItemsLayout in CV2 by @Ahamed-Ali in
#28890
* [Windows] - Fix Visual State Issue with Picker TextColor After
Navigation by @prakashKannanSf3972 in
#28746

### Dependency Updates
* [Windows] Upgrade to Windows App SDK 1.7 by @MartyIX in
#28499

### Testing
* [Testing] Feature Matrix UITest Cases for CollectionView EmptyView
Feature by @NafeelaNazhir in #28679
* Fixed Test case failure in PR 29037 - [2025/04/21] Candidate by
@HarishKumarSF4517 in #29049

**Full Changelog**:
main...inflight/candidate


For more information about inflight process check
https://github.com/dotnet/maui/wiki/Inflight-Branch-Process
@github-actions github-actions bot locked and limited conversation to collaborators May 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info area-essentials-filepicker community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

7 participants