Flutter_file_picker: FileType.CUSTOM does not work with any file extension

Created on 1 Jan 2019  Â·  38Comments  Â·  Source: miguelpruivo/flutter_file_picker

In my app I need support for .csv and .dat file extensions (dat is a backup format in my app, it is actually a zip but I want to separate it from other zip files by file extension). Neither csv or dat seems to work with file_picker (tested in Android). Is there some platform limitation for that "custom" is not actually custom, but it is still limited to few well known file types like pdf, zip etc. If possible it would be much better that file_picker allows any file extension and just filters files by that.

bug suggestion

Most helpful comment

Anyway, when I have some time I’ll take a further look into it and see what I can do, if possible with custom MIME/UTI. For that matter I’ll leave this issue opened. As of now it will stick as it is for a while.

Thank you for the suggestion and happy new year!

All 38 comments

Hi. I understand what you’re trying to achieve, but for that a custom File Provider and explorer would probably be needed, which isn’t actually the purpose of this plugin.

This is intended to use the native explorers with filters for the supported MIME types on Android or UTI’s on iOS.

If the file you want to open is not supported, you can always choose ALL which will display all the files without filtering and validate it yourself within the app (e.g. if the returned file doesn’t match the required extension show a warning and open picker again).

OK I understand. I think I can live with this limitation, I will use ALL as you suggested.

Anyway, when I have some time I’ll take a further look into it and see what I can do, if possible with custom MIME/UTI. For that matter I’ll leave this issue opened. As of now it will stick as it is for a while.

Thank you for the suggestion and happy new year!

Great, thanks! Happy new year to you too!

+1 I need to pick .json file too

@karnadii you should be able to pick json extension by doing:

FilePicker.getFilePath(type: FileType.CUSTOM, fileExtension: 'json’);

Have you already tried?

@miguelpruivo i have ,

 [FilePicker] Platform exception: PlatformException(FilePicker, Unsupported filter. Make sure that you are only using the extension without the dot, (ie., jpg
instead of .jpg). This could also have happened because you are using an unsupported file extension.  If the problem persists, you may want to consider using FileType.ALL instead., null)

@karnadii, that’s weird because json is actually a supported content file type. Is this happening on iOS, Android, or both? Can you check that?

Nevertheless, with FileType.ALL you are able to pick it, right?

Thank you.

@miguelpruivo using android, yes i use FileType.ALL and then validate it within the app

I dont have iOS so I can only confirm for android

Right. I’ll take a look into it whenever I got some time. Thank you @karnadii.

Maybe the filetype should be an array of files types.

@pcegarra yes, that’s one of the upcoming requested features.

@miguelpruivo when do you think the array of file types will be supported?

@jamesmoore255 I got have to have some time to implement it, I can't really tell. Can be this week, can be this month... 😞 But it's definitely the next feature to add to this plugin.

Sorry for taking a while.

No problems @miguelpruivo, I'll keep an eye out for when it is finished!

@miguelpruivo it's implemented(array of file types ) or still remaining?

It’s on the todo list @Zeeshan0201

@miguelpruivo okay, please let us know when it's completed.thanks in advance.

Will I be expected to provide all purpose strings on iOS if I use FileType.ALL? My app is using FileType.ALL (because of unsupported extensions) and when I tried to upload my binary to the App Store, it got rejected because it was missing the NSPhotoLibraryUsageDescription purpose string in Info.plist.
I don't know where/how these purpose strings show up (because I've been using the app only on my test device where everything goes) but it would be a significant disadvantage to using FileType.ALL as a workaround for unsupported extensions.

@FineTillYouCameAlong you are using a package that allows you to access the gallery thus you need to provide the proper entitlements for that because Apple doesn’t know if you’ll actually be picking files from it.

That will happen with every package that uses any kind of functionality, however, the user won’t be notified or allow those permissions unless you explicitly use it on your app.

I am having a similar issue, but unable to use the FilePicker at all (Android emulator).

First I tried:

var path = FilePicker.getFilePath(type: FileType.CUSTOM, fileExtension: 'json’);

"Unsupported filter. Make sure that you are only using the extension without the dot, (ie., jpg instead of .jpg). This could also have happened because you are using an unsupported file extension. If the problem persists, you may want to consider using FileType.ALL instead."

var path = await FilePicker.getFilePath(type: FileType.ANY);

"No implementation found for method ANY on channel file_picker"

What I really need is to prompt the user to pick a json file from a folder under getExternalStorageDirectory().path:

var backupPath = join((await getExternalStorageDirectory()).path, 'archive');

I just saw that specifying a folder is not currently supported (in #99), which is too bad - it would be extremely useful.

hi, any news about the fix? I still have this issue on version 1.5.0+2

@romathebest not yet, there are a couple of things on the line to be made, however, this plugin uses the supported UTI's, I'm not quite sure why it wouldn't support some files. Which type are you trying and in which platform/device? Thank you.

@miguelpruivo I am trying to show only .db files with SQLite data. Android 10 - Samsung s9 sm g960f

I'm using 1.5.1 version. I can't show only kml and gpx files with custom parameter.

FilePicker.getFilePath(type: FileType.custom, fileExtension: 'gpx');
FilePicker.getFilePath(type: FileType.custom, fileExtension: 'kml');

Library gives platform exception;

Platform exception: PlatformException(Unsupported file extension, Make sure that you are only using the extension without the dot, (ie., jpg instead of .jpg). This could also have happened because you are using an unsupported file extension. If the problem persists, you may want to consider using FileType.ALL instead., null)

I was using any parameter in old version and it's was working.

FilePicker.getFilePath(type: FileType.any, fileExtension: 'gpx');
FilePicker.getFilePath(type: FileType.any, fileExtension: 'kml');

Should may i downgrade version?

@Adem68 it's not working for a while, this issue opened more then a year ago
Right now you can use only FileType.any for files with your custom extensions

Thx for reply @romathebest i tried with FileType.any then not worked.

@Adem68 you need to use FileType.any and don't specify an extension at all. That's on the Wiki.

@miguelpruivo I have checked code. There is getMimeTypeFromExtension() on android and it has limited extensions support. It changed in each version of android. For example, you can check list for android 7

I think there should be work around not to use it and set extensions manually

@romathebest sure, that's what this issue is all about, actually.

As a suggestion, if you want to manually check what codec a file is, you can use the ffmpeg library (https://pub.dev/packages/flutter_ffmpeg). For some things it may be an overkill to use it, but it's very reliable.

@DebugTheCode I'm familiar with ffmpeg, however, it's an heavy package to be bundled with and also has restrictions on minor iOS version for Flutter (I believe iOS 11). I think that it should be up to the user to use whatever he wants because some may want to add compression, check codecs and so on while others don't.

@miguelpruivo I agree. That's why I warned for the possible overkill.

@miguelpruivo I have checked code. There is getMimeTypeFromExtension() on android and it has limited extensions support. It changed in each version of android. For example, you can check list for android 7

I think there should be work around not to use it and set extensions manually

I looked at the link supplied, and on line 314 the 'csv' type is an included mime type, yet your file picker refuses to see the *.csv extension when used with custom.
314 add("text/comma-separated-values", "csv");
I need to limit users to the correct file type. What's the use of a file picker with extensions if they appear greyed out. Changing the extension of the file to .xls makes it visible to the file picker if .xls is used as the extension, but remains greyed if csv. Why can this not be fixed on your side.

@wreyford the plugin just acts as a bridge between Flutter and iOS/Android by launching their own pickers with a few parameters one of which is the file type filter. Thing is, some Androids will honor those filters whereas others don't, you can read moer about it here.

Think of the filtering as a nice to have but you should always validate on your side, thus, discarding all unsupported files. I can't by any means force whatever file explorer will launch with the picker, to accept/refuse those filters, because some users even have 3rd party explores such as ESExplorer that can be used along with file picker.

There is no fix for this bug, but it was closed ?

@Aravin that’s just a platform bottleneck. There’s no definite fix that can be applied here other than creating a custom explorer from scratch which wasn’t the intended behavior from the plugin since the beginning.

I’m sorry for any inconvenience.

Was this page helpful?
0 / 5 - 0 ratings