Resolve DocumentPicker result

Hi, sry for my Eng. I use DocumentPicker and it returns uri with “content://” scheme. As I know to resolve such uris I need to use ContentResolver (for Android) ContentResolver  |  Android Developers. I can’t find any components/utilities in Expo SDK responsible for it.

And I think the only way to use DocumentPicker is detach SDK and look for a react native module to resolve “content” uris returned by DocumentPicker.

Or is there another way? Thanks.

1 Like

I don’t think this is supported in Expo right now. There’s the FileSystem API but I believe it doesn’t use ContentResolver.

@progmonster did you find this component to convert content:// to file:// ?

Hi @flieks! All react-native npm modules I’d found for document selection didn’t work for me when I used Expo. I had to give up Expo and rewrite in pure react native.

The problem occurs because onActivityResult is not called inside my or any react-native module in Expo. This is because (as I understood and debugged) such calls handled inside Expo framework logic and for some reason are not passed to my module’s onActivityResult.

Sry for my English

@progmonster interesting. Thanks. Which RN document picker did you use? I need to let user pick a pdf and show it before sending it to our server. So it would be nice to scan all hdd folders with Expo.FileSystem for PDF’s and show them in a list. User picks one and we have file:// url. Is that possible you think ?

Greetings

@flieks I’d wrote my own rn-plugin and it also doesn’t work as a part of Expo’app. It works only for pure react native app. I’m sry I hadn’t investigated deep in the reason of this.

Source code of my rn-plugin:
https://gist.github.com/progmonster/ff8ea9bc40f55ca1cd97c84419117605#file-expmodule-java-L32

Thanks @progmonster . I’m trying to implement your code :slight_smile: (not an android studio expert) with detached expo app. As i don’t see http3 (issue in rn-fetch-blob with expo), this can maybe work.
I commented in your github… It doesn’t fire the then() or catch() callbacks…

Is it easy to show the base64 result to the user ?

Hi @flieks! Sry for late answer. My code is not worked with Expo even in detached mode. I’d written my app in pure RN. This is because even in detached mode the main application java class still inherited from some Expo class and in my case this leads to the problem when activity result events are not passed to my handlers inside my native modules. But may be this will work for you. I don’t know…

The result my plugin returns is base64 encoded content of selected file. You can find some npm plugins that can convert to blobs or may be some pdf-plugins can work with base64 directly.

Sry @flieks didn’t see your comments on gist.github. Sure, you can remove getSimList method, this is not related to your task.

Yes you need to add ExpReactPackage to packages list in MainApplication class. If you need I can provide some examples.

“it doesn’t go in the onActivityResult of BaseActivityEventListener” as in my case this may be related with Expo (Main class inherited from some Expo class). My module working only on pure RN (where Main app class and Activity class inherit from react native classes and android classes without any Expo)

@flieks This is strange that you have minified code in the error stack trace you’d provided in gist. In development mode you should see non-minified java code that of course more informative. Is this from production?

08-29 21:51:24.158 25301-25359/? E/SuperpacksMgr: atp: Failed to sync manifest for lstm
java.lang.NullPointerException: Pack lstm:lstm_prediction_nl_20170411 is not part of manifest lstm.1
at dtw.a(PG:5)
at dte.a(PG:7)
at dty.a(PG:99)
at dua.a(Unknown Source)
at fds.a(PG:7)
at fdr.run(PG:33)
at few.run(PG:3)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:776)

Thanks @progmonster for help.
I could get file:// from other native solution
code is here: Get real path from URI, Android KitKat new storage access framework - Stack Overflow
And i could show a pdf to the user with native pdfView. (I let them pick a pdf, show it and upload to server).
Now my last problem is to upload it with formData. I tried through fetch, xhr, axios, superagent, form-date.
I think it’s expo bug because this should have worked:

fd.append('filename', {
              uri: 'file://' + this.state.pdfPath,
              type: 'application/pdf'
            });

without that file, it sends fine with the other params.
So now i am using your function to convert it to base64 and send that as plain text to our API…I see no other way.

I’m not using production mode. I’m still in debug, this is with cable, detached expo. (LAN exp)

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.