Flutter_file_picker: Cannot open document with URI: com.android.providers.downloads.documents .

Created on 22 Nov 2018  路  34Comments  路  Source: miguelpruivo/flutter_file_picker

Cannot open document with URI: com.android.providers.downloads.documents.
App crashes when attaching document of above URI with below error :

I/FilePicker( 7038): Checking permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker( 7038): Checking permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker( 7038): URI:content://com.android.providers.downloads.documents/document/2350
E/FilePathPicker( 7038): +++ API 19 URI :: content://com.android.providers.downloads.documents/document/2350
E/FilePathPicker( 7038): +++ Document URI
E/FilePathPicker( 7038): +++ Downloads External Document URI
D/AndroidRuntime( 7038): Shutting down VM
E/AndroidRuntime( 7038): FATAL EXCEPTION: main
E/AndroidRuntime( 7038): Process: com.coromandel.ideaspace, PID: 7038
E/AndroidRuntime( 7038): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=43, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/2350 flg=0x43 }} to activity {com.coromandel.ideaspace/com.coromandel.ideaspace.MainActivity}: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/2350
E/AndroidRuntime( 7038):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4440)
E/AndroidRuntime( 7038):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4484)
E/AndroidRuntime( 7038):    at android.app.ActivityThread.-wrap19(Unknown Source:0)
E/AndroidRuntime( 7038):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1743)
E/AndroidRuntime( 7038):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 7038):    at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime( 7038):    at android.app.ActivityThread.main(ActivityThread.java:6753)
E/AndroidRuntime( 7038):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 7038):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
E/AndroidRuntime( 7038):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/AndroidRuntime( 7038): Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/2350
E/AndroidRuntime( 7038):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
E/AndroidRuntime( 7038):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
E/AndroidRuntime( 7038):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:432)
E/AndroidRuntime( 7038):    at android.content.ContentResolver.query(ContentResolver.java:793)
E/AndroidRuntime( 7038):    at android.content.ContentResolver.query(ContentResolver.java:712)
E/AndroidRuntime( 7038):    at android.content.ContentResolver.query(ContentResolver.java:670)
E/AndroidRuntime( 7038):    at com.mr.flutter.plugin.filepicker.FilePath.getDataColumn(FilePath.java:121)
E/AndroidRuntime( 7038):    at com.mr.flutter.plugin.filepicker.FilePath.getForApi19(FilePath.java:66)
E/AndroidRuntime( 7038):    at com.mr.flutter.plugin.filepicker.FilePath.getPath(FilePath.java:26)
E/AndroidRuntime( 7038):    at com.mr.flutter.plugin.filepicker.FilePickerPlugin$1.onActivityResult(FilePickerPlugin.java:49)
E/AndroidRuntime( 7038):    at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:210)
E/AndroidRuntime( 7038):    at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:139)
E/AndroidRuntime( 7038):    at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:138)
E/AndroidRuntime( 7038):    at android.app.Activity.dispatchActivityResult(Activity.java:7317)
E/AndroidRuntime( 7038):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4436)
E/AndroidRuntime( 7038):    ... 9 more
W/OPDiagnose( 7038): getService:OPDiagnoseService NULL
D/OSTracker( 7038): OS Event: crash
bug ready to deploy

All 34 comments

@sonathati thank you for your feedback, may I ask what is the source of the file?

Miguel

same issue for pdf file in Download

@NukanTran what鈥檚 the path from the file you鈥檙e trying to load? Can you post your logs?

I/FilePicker( 6736): Checking permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker( 6736): URI:content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Fa.pdf
E/FilePathPicker( 6736): +++ API 19 URI :: content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Fa.pdf
E/FilePathPicker( 6736): +++ Document URI
E/FilePathPicker( 6736): +++ Downloads External Document URI
D/AndroidRuntime( 6736): Shutting down VM
E/AndroidRuntime( 6736): FATAL EXCEPTION: main
E/AndroidRuntime( 6736): Process: com.example.mytest, PID: 6736
E/AndroidRuntime( 6736): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=43, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/a.pdf flg=0x43 }} to activity {com.example.mytest/com.example.mytest.MainActivity}: java.lang.NumberFormatException: For input string: "raw:/storage/emulated/0/Download/a.pdf"
E/AndroidRuntime( 6736): at android.app.ActivityThread.deliverResults(ActivityThread.java:4324)
E/AndroidRuntime( 6736): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367)
E/AndroidRuntime( 6736): at android.app.ActivityThread.-wrap19(Unknown Source:0)
E/AndroidRuntime( 6736): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
E/AndroidRuntime( 6736): at android.os.Handler.dispatchMessage(Handler.java:105)
E/AndroidRuntime( 6736): at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime( 6736): at android.app.ActivityThread.main(ActivityThread.java:6541)
E/AndroidRuntime( 6736): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6736): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/AndroidRuntime( 6736): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
E/AndroidRuntime( 6736): Caused by: java.lang.NumberFormatException: For input string: "raw:/storage/emulated/0/Download/a.pdf"
E/AndroidRuntime( 6736): at java.lang.Long.parseLong(Long.java:590)
E/AndroidRuntime( 6736): at java.lang.Long.valueOf(Long.java:804)
E/AndroidRuntime( 6736): at com.mr.flutter.plugin.filepicker.FilePath.getForApi19(FilePath.java:64)
E/AndroidRuntime( 6736): at com.mr.flutter.plugin.filepicker.FilePath.getPath(FilePath.java:26)
E/AndroidRuntime( 6736): at com.mr.flutter.plugin.filepicker.FilePickerPlugin$1.onActivityResult(FilePickerPlugin.java:49)
E/AndroidRuntime( 6736): at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:210)
E/AndroidRuntime( 6736): at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:139)
E/AndroidRuntime( 6736): at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:138)
E/AndroidRuntime( 6736): at android.app.Activity.dispatchActivityResult(Activity.java:7235)
E/AndroidRuntime( 6736): at android.app.ActivityThread.deliverResults(ActivityThread.java:4320)
E/AndroidRuntime( 6736): ... 9 more

this is my logs

@NukanTran Thank you. What鈥檚 the android version?

Android 8.0 in Genymoution

Android 8.0 in Genymoution

@NukanTran I might take a look into it later on. However, you are free to use the version on the beta branch because it's ahead of the master and has some updates.

@NukanTran @sonathati @zean00 apparently there are some files started with "raw" string that may lead to this issue on Android 8.0. Doesn't seem to happen with other versions though.

I couldn't replicate the issue, however I'm PR a fix to the beta branch and maybe later today merge a version 1.0 on the master along with dart pub update.

Let me know if it worked for you.

edit: version 1.0 it's now live with the fixes on dart pub, thank you for your feedback.

@miguelpruivo I just tried 1.0.2 from pub and build fails

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':file_picker:debugCompileClasspath'.
> Failed to transform file 'flutter.jar' to match attributes {artifactType=android-classes} using transform JarTransform
   > Transform output file /Users/miguelruivo/DevTools/flutter/bin/cache/artifacts/engine/android-arm64/flutter.jar does not exist.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 17s
Finished with error: Gradle task assembleDebug failed with exit code 1

Flutter version:
Flutter (Channel beta, v0.11.9, on Mac OS X 10.13.6 17G3025, locale en-IN)

@sonathati glad that you鈥檝e spotted it. I know what it is, that鈥檚 something that shouldn鈥檛 had been committed, probably due to a later git squash, my bad. I鈥檒l fix it later today.

@sonathati everything should be working fine by now on 1.0.3, let me know if you find anything else.
Sorry for any inconvenience.

@miguelpruivo I am not able to get the file name when picked from open from view. But Iam able to retrieve the file name when attached from file manager available in the drawer

I/FilePicker( 9298): Checking permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker( 9298): URI:content://com.android.providers.downloads.documents/document/3023
E/FilePathPicker( 9298): +++ API 19 URI :: content://com.android.providers.downloads.documents/document/3023
E/FilePathPicker( 9298): +++ Document URI
E/FilePathPicker( 9298): +++ Downloads External Document URI
E/FilePathPicker( 9298): +++ Something went wrong while retrieving document path: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3023
I/FilePicker( 9298): Loaded file from cloud created on:/data/user/0/com.coromandel.ideaspace/cache/Document
I/FilePicker( 9298): Absolute file path:/data/user/0/com.coromandel.ideaspace/cache/Document
I/flutter ( 9298):  /data/user/0/com.coromandel.ideaspace/cache/Document
I/FilePicker( 9298): Checking permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker( 9298): URI:content://com.android.externalstorage.documents/document/primary%3ADownload%2F009E2D7C02DF488285C3409DC93A52D7.pdf
E/FilePathPicker( 9298): +++ API 19 URI :: content://com.android.externalstorage.documents/document/primary%3ADownload%2F009E2D7C02DF488285C3409DC93A52D7.pdf
E/FilePathPicker( 9298): +++ Document URI
E/FilePathPicker( 9298): +++ External Document URI
E/FilePathPicker( 9298): +++ Primary External Document URI
I/FilePicker( 9298): Absolute file path:/storage/emulated/0/Download/009E2D7C02DF488285C3409DC93A52D7.pdf
I/flutter ( 9298): /storage/emulated/0/Download/009E2D7C02DF488285C3409DC93A52D7.pdf

@sonathati I believe that is already fixed in the beta branch, could you give it a try? (You鈥檒l need to add to your pubspec by using a git ref dependency).

@miguelpruivo I have tried in latest beta branch by adding git ref dependency in my pubspec. But still not able to get the file name. Following are the logs

I/FilePicker(31444): Checking permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker(31444): Requesting permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker(31444): Checking permission: android.permission.WRITE_EXTERNAL_STORAGE
I/FilePicker(31444): URI:content://com.android.providers.downloads.documents/document/3464
E/FilePathPicker(31444): +++ API 19 URI :: content://com.android.providers.downloads.documents/document/3464
E/FilePathPicker(31444): +++ Document URI
E/FilePathPicker(31444): +++ Downloads External Document URI
E/FilePathPicker(31444): +++ Something went wrong while retrieving document path: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3464
I/FilePicker(31444): Loaded file from cloud created on:/data/user/0/com.coromandel.ideaspace/cache/Document
I/FilePicker(31444): Absolute file path:/data/user/0/com.coromandel.ideaspace/cache/Document
I/flutter (31444): /data/user/0/com.coromandel.ideaspace/cache/Document

Hi again @sonathati , this seems to be a very specific/tricky issue that might be related to the path of downloads folder or a disabled download manager. Anyway, I've committed an update that tries to solve or, at least, try to understand the issue. Could you clean & build with the beta again, to give it a try?

Thank you.

@miguelpruivo I could see issue still exists with the latest update, beta branch.
Issue is not seen for the same file attached from different view. Attaching the logs for file StoreList.pdf for both uploading URIs

Working case:

I/FilePicker(32236): URI:content://com.android.externalstorage.documents/document/primary%3ADownload%2FStoreList.pdf
E/FilePathPicker(32236): +++ API 19 URI :: content://com.android.externalstorage.documents/document/primary%3ADownload%2FStoreList.pdf
E/FilePathPicker(32236): +++ Document URI
E/FilePathPicker(32236): +++ External Document URI
E/FilePathPicker(32236): +++ Primary External Document URI
I/FilePicker(32236): Absolute file path:/storage/emulated/0/Download/StoreList.pdf

Not working case:

I/FilePicker(32236): URI:content://com.android.providers.downloads.documents/document/3006
E/FilePathPicker(32236): +++ API 19 URI :: content://com.android.providers.downloads.documents/document/3006
E/FilePathPicker(32236): +++ Document URI
E/FilePathPicker(32236): +++ Downloads External Document URI
E/FilePathPicker(32236): +++ Something went wrong while retrieving document path: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3006
I/FilePicker(32236): Loaded file from cloud created on:/data/user/0/com.coromandel.ideaspace/cache/Document
I/FilePicker(32236): Absolute file path:/data/user/0/com.coromandel.ideaspace/cache/Document

Can I ask you where actually you鈥檙e trying to load the second path? I remember having an issue where some androids would display email attachments on the recent files but the files weren鈥檛 actually there, it was like a placeholder.

Also @sonathati, can you clean and try with file_picker: ^1.1.1 that is already on the dart pub?

@miguelpruivo I have noticed that this bug started from image_picker provide by flutter team. You are right about the disabled downloads manager. But one thing I noticed in your version was that file picker works great when the file type is set to any. But as soon as file type is set IMAGE, it fails and gives the fatal exception. I think when we fail to retrieve the file path, we must copy the file to the cache directory and then get the path from there. It seems you are already implementing this for documents but since you are using image_picker as the source for picking files, it fails.

Thank you for the insights @pushangupta can you confirm if you are using FileType.CAMERA or FileType.IMAGE when this issue happens @sonathati?

@miguelpruivo FileType.IMAGE

@miguelpruivo Brother I did a little experiment. I changed the FileType to CUSTOM and gave file extension as JPG and guess what.. It fetched the exact same file it was failing on. Just a quick suggestion. If multiple file types(like JPG, PNG, SVG or JPEG) could be supported at the same time it would be better

@pushangupta that鈥檚 why it has the FileType.IMAGE, so it can filter all image file types at once, otherwise it wouldn鈥檛 make sense.

@miguelpruivo I mean, FileType.IMAGE surely uses image_picker... right? I am trying to avoid image_picker. Moreover if, for example, I wanted to select docs of extensions pdf, docx or ppt only what can I do?

@pushangupta right now you鈥檇 have to use FileType.ALL for that matter, but it鈥檚 a good suggestion that in a future update I add a FileType.DOC or so that will gather all of those file types in a filter at once.

@miguelpruivo I had faced this issue with FileType.PDF
I have tried with file_picker: ^1.1.1 and its working fine for documents(using FileType.CUSTOM and fileExtension:'pdf') and for other FileTypes aswell except for FileType.IMAGE.

For FileType.IMAGE my App crashes when trying to upload image with URI: content://downloads/public_downloads/3411
Below is the Exception:

D/AndroidRuntime(10073): Shutting down VM
E/AndroidRuntime(10073): FATAL EXCEPTION: main
E/AndroidRuntime(10073): Process: com.coromandel.ideaspace, PID: 10073
E/AndroidRuntime(10073): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/3411 flg=0x1 }} to activity {com.coromandel.ideaspace/com.coromandel.ideaspace.MainActivity}: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3411
E/AndroidRuntime(10073):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4440)
E/AndroidRuntime(10073):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4484)
E/AndroidRuntime(10073):    at android.app.ActivityThread.-wrap19(Unknown Source:0)
E/AndroidRuntime(10073):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1743)
E/AndroidRuntime(10073):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(10073):    at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime(10073):    at android.app.ActivityThread.main(ActivityThread.java:6753)
E/AndroidRuntime(10073):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10073):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
E/AndroidRuntime(10073):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/AndroidRuntime(10073): Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3411
E/AndroidRuntime(10073):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
E/AndroidRuntime(10073):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
E/AndroidRuntime(10073):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:432)
E/AndroidRuntime(10073):    at android.content.ContentResolver.query(ContentResolver.java:793)
E/AndroidRuntime(10073):    at android.content.ContentResolver.query(ContentResolver.java:712)
E/AndroidRuntime(10073):    at android.content.ContentResolver.query(ContentResolver.java:670)
E/AndroidRuntime(10073):    at io.flutter.plugins.imagepicker.FileUtils.getDataColumn(FileUtils.java:117)
E/AndroidRuntime(10073):    at io.flutter.plugins.imagepicker.FileUtils.getPathFromLocalUri(FileUtils.java:69)
E/AndroidRuntime(10073):    at io.flutter.plugins.imagepicker.FileUtils.getPathFromUri(FileUtils.java:41)
E/AndroidRuntime(10073):    at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChooseImageResult(ImagePickerDelegate.java:395)
E/AndroidRuntime(10073):    at io.flutter.plugins.imagepicker.ImagePickerDelegate.onActivityResult(ImagePickerDelegate.java:375)
E/AndroidRuntime(10073):    at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:210)
E/AndroidRuntime(10073):    at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:139)
E/AndroidRuntime(10073):    at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:138)
E/AndroidRuntime(10073):    at android.app.Activity.dispatchActivityResult(Activity.java:7317)
E/AndroidRuntime(10073):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4436)
E/AndroidRuntime(10073):    ... 9 more
W/OPDiagnose(10073): getService:OPDiagnoseService NULL
D/OSTracker(10073): OS Event: crash

@sonathati this looks like an issue from image_picker plugin then, since that is what鈥檚 used when type is either IMAGE or CAMERA. You may want to report it on the image_picker official repo.

_info_: related issue from image_picker repo: https://github.com/flutter/flutter/issues/21863

@miguelpruivo there is a fix available as separate package.
Can you create a temporary branch with reference to https://pub.dartlang.org/packages/image_picker_modern instead of image_picker so that we can reference to that branch directly via git in pubspec?

@tiholic thank you for pointing it. It may be a possibility, I'll take a look when I have sometime, feel free to give it a try and PR if you find it fixing the problem while keeping all of the required features.

Sure, I'll try and let you know

It works great. I've tested for images, videos and pdf's.

https://github.com/miguelpruivo/plugins_flutter_file_picker/pull/26

@tiholic does it fix this specific issue?

Yes, now we can pick all types of files from downloads

https://github.com/flutter/flutter/issues/21863

Issue closed, you can update the version.

Was this page helpful?
0 / 5 - 0 ratings