Flutter_file_picker: Flutter Web: allowedExtensions seem not to work

Created on 11 Oct 2020  Â·  27Comments  Â·  Source: miguelpruivo/flutter_file_picker

As in the title. I allowed only some extenions, but no images extensions. It works good on computer (you can't choose images), but on mobile (I only checked it on Android because I don't have iPhone) you can literally pick every file.

File picker and Flutter on newest versions.

Also - is there a way to disable user to select "All files" in file picker on computer?

new issue

All 27 comments

So, as I read here, it may be a problem with mobile's producer file picker. I asked my friend if he can check it on iPhone and I will posts results here.

Also - is there a way to disable user to select "All files" in file picker on computer?

I don't have answer for that question yet

@Henzelix what’s the kind of files that you’re having an issue with?

@miguelpruivo I only accepted Office file, like xlsx, docx, pdf, etc. But as I said in my comment, it may be the problem that you described in Wiki that's only on Android. As I said, my freind will check that on iPhone

@Henzelix on ios that issue doesn’t happen. It only happens on android and this is the first time I’ve heard about it on web.

How are you picking?

@Henzelix any news on this?

@miguelpruivo yes, sorry for latency. It turns out IOS even gives you an option to choose image picker instead of file picker. As long as I could filter files extensions on the client side after choosing file on Android or Web, giving user opportunity to browse only pictures and then telling him that I don't support pictures isn't really good for UX.

image

Sorry for no English UI, buttons are:

  1. Take a photo or record a video
  2. Image Gallery
  3. Browse

@Henzelix I don't get your issue then. Mind to elaborate? Thank you!

@Henzelix I don't get your issue then. Mind to elaborate? Thank you!

@miguelpruivo Issue is that I didn't allow jpg, png, etc. but I can still choose them even on iOS

@Henzelix show me how are you picking please.

@miguelpruivo
FilePickerResult result = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: ['jpg', 'pdf', 'doc'], );

I mean I have different allowedExtensions, but code is the same (from ur readme.md)

@Henzelix hum, weird. Which iOS version?

@miguelpruivo its iPhone 6 so probably iOS12

@Henzelix where does that picker sheet come from? The one that says camera, image gallery or browse?

@miguelpruivo i dont know if i get you, but that button has onPressed() function that runs my code and this sheet pops out. I was probably using Google Chrome but Im not sure

image

I can check it tomorrow on Safari but idk if that would change smth, still some people use chrome on ios so it isnt nice to tell them to switch to safari

@Henzelix on Android it works fine?!

@miguelpruivo

As in the title. I allowed only some extenions, but no images extensions. It works good on computer (you can't choose images), but on mobile (I only checked it on Android because I don't have iPhone) you can literally pick every file.

@Henzelix looks like a limitation from mobile browsers. I’m not actually sure on how I’m going to handle it.

@miguelpruivo ok, thanks for help, I'll also will think about that

Hello.

I have the problem also on my OnePlus 6 (android 10)
I have the following :

final FilePickerResult pickerResult = await FilePicker.platform.pickFiles(
      allowMultiple: false,
      allowedExtensions: ["jpg", "JPG"],
      type: FileType.custom,
    );

But i can choose to select from the gallery, and when it uses the gallery, I can pick a .png file.

Not sure if it's related to the issue you linked in the Troubleshot section of the wiki

@Extazx2 you don't have to provide both upper and lowercase extensions. Lower is enough. This is related to this Android limitation described on the troubleshooting. I'm sorry. You should always double step validate the picked files — iterate through all and check the extension property to check if the user picked valid files. If not, discard and present an informative message, for example.

@Extazx2 @miguelpruivo You can do smth like this:
List<String> _extensions = ['doc', 'pdf', 'docx', 'xlsx', 'xls', 'xltx', 'pptx', 'ppt', 'odt', 'txt', 'jpg', 'png'];

String _fileExtension = pickedFile,name.split('.').last.toString();

else if(!_extensions.contains(_fileExtension)){ setState(() { error = 'xxxxxx'; fileName = 'xxxxx';

@miguelpruivo, thank you for the plugin.

I am also facing the same problem with FileType.custom which is behaving unexpectedly.

extensions: ["pdf", "doc", "docx"], type: FileType.custom

With the above config, it is working properly with Recent Files, Drive, and Download folders but it is showing Google Photos in the drawer menu where I can select any kind of photos, videos.

Checked In Android

Please let me know If anything I can do to fix it.
Thanking you all!

@pandeykamlendra42 if I could count the number of times I've forwarded people to that particular limitation on the troubleshooting area of the Wiki... 😄

Basically, that's a limitation. It's up to the apps (in this case Google Photos) to decide whether they will honor or not the requested filters. Unfortunately, most of the times, they don't care. So you should always double check on your end.

Closing as this looks like a mobile browser limitation that I can't see a way at this point to go around this. I'll keep an eye on this and see if anyone else may report it as well.

As of now, double validating on your end, is always the best bet.

@Henzelix thank you for your input, let me know if you find anything else that may contribute for fixing this edge case, if so, let me know or issue a PR.

Thank you for your comprehension!

Was this page helpful?
0 / 5 - 0 ratings