sidlatau / flutter_document_picker

Allows user pick a document. Picked document is copied to app temporary directory. Optionally allows pick document with specific extension only.
Apache License 2.0
41 stars 29 forks source link

File Extension filter not working #5

Closed ThinkDigitalSoftware closed 6 years ago

ThinkDigitalSoftware commented 6 years ago

I entered an allowedFileExtension in the params, but it didn't filter the list.

screen shot 2018-09-21 at 9 28 12 pm
sidlatau commented 6 years ago

allowedFileExtensions parameter does not filter files that are shown in the picker. I wasn't able to find an easy way to do that in Android. In iOS allowedUtiTypes parameter could be used for that - then not wanted files will be disabled in the picker.

When file is picked its extension is checked using allowedFileExtensions parameter. Then file is copied to app temp directory. Copied file path is returned as result. If picked file extension is not in allowedFileExtensions list then extension_mismatch error is returned.

ThinkDigitalSoftware commented 6 years ago

Oh.... How much control do you have over what shows up in the list?

sidlatau commented 6 years ago

Files can be filtered by MIME types in Android. I just released plugin v1.1.0 version where I added optional parameter allowedMimeType. Previously */* MIME type was used, now it becomes customisable.

As I understand you want to select files with custom extensions *.db, yes? The closest MIME type that works for me is application/octet-stream. Not all files will be filtered but for example it would not show images, videos, text files there. In iOS you can register custom UTI type (instructions there).

Example:

FlutterDocumentPickerParams params = FlutterDocumentPickerParams(      
  allowedFileExtensions: ['db'],
  allowedUtiTypes: ['your.domain.db'],
  allowedMimeType: 'application/octet-stream',
);

final path = await FlutterDocumentPicker.openDocument(params: params);

Does allowedMimeType parameter solve your problem?

ThinkDigitalSoftware commented 6 years ago

It sounds like it will be closer to what I'm looking for. I'll try it out when I get on my computer again. Thank you! -- Think Digital 323-638-9448 760-678-8833 Facebook.com/ThinkDigitalRepair

ThinkDigitalSoftware commented 6 years ago

It doesn't solve the problem, but it definitely helps. Could you also support a starting directory as well? Like, initialDirectory: "/sdcard"?

_Sent from my Galaxy S9+ using FastHub

sidlatau commented 6 years ago

I found in documentation:

Callers can set a document URI through DocumentsContract.EXTRA_INITIAL_URI to indicate the initial location of documents navigator. System will do its best to launch the navigator in the specified document if it's a folder, or the folder that contains the specified document if not.

So it seems it is possible to set initial directory, at least in Android part. Need to check is it possible in iOS part.

Currently I have no plans to add this initial directory functionality to this plugin but PRs are welcome!

ThinkDigitalSoftware commented 6 years ago

Ok, I'll see if I have a need in my app for it. But it seems like there could be a strong use case, for example if someone needs to find a download or if they want to start in the SD card always. If I need it, I'll try to submit a PR