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.27k stars 1.76k forks source link

Maui FilePicker results in This platform does not support this file type. #9394

Open julianadormon opened 2 years ago

julianadormon commented 2 years ago

Description

I am building a desktop app in .NET Maui which targets Windows and MacOS. When using the built-in FilePicker on Mac (Catalyst) I get the following error:

{System.PlatformNotSupportedException: This platform does not support this file type. at Microsoft.Maui.Storage.FilePickerFileType.GetPlatformFileType(DevicePlatform platform) at Microsoft.Maui.Storage.FilePickerFileType.get_Value() at Microsoft.Maui.S…}

I have tried multiple file types, including csv, jpg, text/csv but nothing works.

`public async Task ImportCSV() { try { var customFileType = new FilePickerFileType( new Dictionary<DevicePlatform, IEnumerable> { { DevicePlatform.WinUI, new[] { ".csv" } }, { DevicePlatform.macOS, new[] {"csv"} } });

        PickOptions options = new()
        {
            PickerTitle = "Please select a csv file",
            FileTypes = customFileType
        };

        var file = await FilePicker.Default.PickAsync(options);

        if (file != null)
        {
            string filePath = AppStateService.fixMacFilePath(file.FullPath);

            AppStateService.AppState.csvFilePath = filePath;

            await InitiateCsvMapping();
        }
    }
    catch (Exception ex)
    {

    }
}`

Steps to Reproduce

  1. Create a new Maui app.
  2. Remove iOS and Android targets from project file.
  3. Execute the shared code

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

MacCatalyst 14.0

Did you find any workaround?

The documentation does say that I should "Enable iCloud capabilities" but does not provide any links or other information regarding this. I did some digging, and found some documentation that says that it necessary to do this via the Entitlements.plist file which I did but it seems to only be relevant when publishing your app to the App store which I am not during development. I don't even care about iCloud right now. I just want to select a CSV file from my own desktop.

Relevant log output

{System.PlatformNotSupportedException: This platform does not support this file type.
   at Microsoft.Maui.Storage.FilePickerFileType.GetPlatformFileType(DevicePlatform platform)
   at Microsoft.Maui.Storage.FilePickerFileType.get_Value()
   at Microsoft.Maui.S…}
julianadormon commented 2 years ago

If I remove the options, I have no problem selecting a csv file, so it CAN pick the right file. Something is not right with the options definition.

julianadormon commented 2 years ago

Furthermore, if I use the default, FilePickerFileType.Images, as a test

PickOptions options = new() { PickerTitle = "Please select a csv file", FileTypes = FilePickerFileType.Images };

This results in the same error.

As does var file = await FilePicker.Default.PickAsync(PickOptions.Images);

ooikengsiang commented 2 years ago

Having the same problem on MacOS as well. ` var pickOptions = new PickOptions() { FileTypes = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable> { { DevicePlatform.WinUI, new[] { ".json", ".json" } }, { DevicePlatform.macOS, new[] { "json", "json" } } }) };

var result = await FilePicker.Default.PickAsync(pickOptions); if (result != null) { // do something } `

Leaving the file type out in pick option do work as a workaround explained above, but no filtering support.

cdavidyoung commented 2 years ago

Same problem here on MacOS. The workaround allows the pick to work without the filtering. I have tested this on Windows and Android and the filtering works.

cdavidyoung commented 2 years ago

I found that if I use MacCatalyst instead of MacOS it works fine:

         var zipFileType = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
                                                  {
                                                     { DevicePlatform.iOS, new[] { "public.archive" } },
                                                     { DevicePlatform.Android, new[] { "application/zip" } },
                                                     { DevicePlatform.WinUI, new[] { "zip" } },
                                                     { DevicePlatform.MacCatalyst, new[] { "zip" } },
                                                        });
         var optionsZip = new PickOptions
            {
               PickerTitle = "Please select a previously backed up zip file",
               FileTypes = zipFileType
            };
julianadormon commented 2 years ago

@cdavidyoung Thank you so much for figuring this out!

MGohil commented 1 year ago

Providing supported file type options disables all those files in File Browser in Android. So, I am unable to pick those files. If I do not mention any file types (filePicker.PickAsync(null)) , it woks good, but shows all files.

I want to restrict to show only supported files to pick Ex. png, jpg, pdf.

image

alelom commented 1 year ago

Can repro the issue.

This is really annoying and needs to be fixed!

drasticactions commented 1 year ago

FYI: Using "MacCatalyst" is the right thing here. "MacOS" refers to AppKit macOS applications, which MAUI Essentials can use.

drasticactions commented 1 year ago

Also redirecting https://github.com/dotnet/maui/issues/13294 here, since it seems like they are general issues around the API here and getting it to work.

@mattleibow I'm not sure if the Android issue here is a bug, or the API being incorrectly used.

Zhanglirong-Winnie commented 11 months ago

Verified this issue with VSM 17.6.7 (build 417). Can repro this issue. image

oracularhades commented 7 months ago

Hey, I'm still getting this issue as well.

SonicScholar commented 5 months ago

Issue https://github.com/dotnet/maui/issues/13294 was marked as a duplicate of this one. However #13294 is Android specific. I'm trying to get "text/csv" to work for the Android platform so the users can upload a .csv file.

If #13294 is being redirected, maybe add the platform/Android tag?

I'll see if I can dig up the list of supported mime types for the native Android file picker control and reference it here. If Google's API doesn't support it, not sure what can be done at the MAUI layer.

afielden commented 4 months ago

I'm trying to do the same as @SonicScholar i.e. allow picking of .csv files only, but all files are non selectable

 var customFiletype =
     new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
     {
         { DevicePlatform.Android, new[] {"csv"} }
     });

 var options = new PickOptions
 {
     PickerTitle = "Please select a CSV file",
     FileTypes = customFiletype
 };
Skarzag commented 2 weeks ago

Same problem here, i'm trying to filter on csv files or on .dat file and they are unselectable (tested on android)