-
-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache files when files comes from contents provider #224
cache files when files comes from contents provider #224
Conversation
a332ed5
to
62617a6
Compare
Isn't this risky if the file is too heavy? Do they expire? |
https://github.com/Elyx0/react-native-document-picker/pull/224/files#diff-523312492e49e2a89c959fc626ac8bcdR209 |
Of course your permissions to a file is time limited and only usable within your application. Even on iOS the native document picker should work that way. The uri provided by a document picker is not supposed to be stored or passed around. You are supposed to get the uri from the picker and then immediately do what you are going to do with the file: upload it, copy it locally and do stuff, or persist permissions if you plan to edit it. If you are editing the file and want to persist permissions, there is an API to do that: If you always copy the file into the local cache then you are causing problems for 2/3 of the user use cases for the document picker. People who are uploading the files and do not need the files cached will now have their cache flooded with junk, even if this eventually gets purged it may result in caches that the app does need to make things run fast getting purged faster than they need to. And as for people who are using the document picker to make an editor, because you have copied the file and are returning a file path it is now impossible for them to edit the original file because they absolutely need the content URI to do so. If you are the 1/3 of use cases and need to copy the file into a local cache, that should be doable at the user level outside of the document picker. i.e. You have the content URI and know immediately when the file has been picked, all you have to do is get the file contents and write them to a local file. RN's |
output.write(buffer, 0, read); | ||
} | ||
output.flush(); | ||
map.putString(FIELD_URI, file.getPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this return a file path instead of a file://
URI breaking consistency with other platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. This has risk if users expect to receive content uri.
Thank you for review.
I have tried some cases using RNFS or RNFB, but in virtual files from like google drive has permission error. Maybe it is provided content uri from another context calling intent of GET_CONTENT. |
RNFS is only made to work with the local filesystem, it's not designed to work with documents picked from other apps. RNFB is poorly written and obsolete. React Native has native support for fetching a content URI to get a Blob. |
Thank you very much and glad to know that. I'll check this and close this pr today when I have time. |
I have struggled for a half of day.
I couldn't get no blob though maybe it is possible uploading contents via formData. So I want to add project directory to inspect more easily for everyone in this repository like as other library projects do. my react-native-info
|
fetch returns a promise for a response, not a Blob. You need to use |
Closes #70 Closes #206
In android, I found these issues due to using content uri via content provider it restricts access to file without the context or services of application instance. So I fix by saving the files the cache directories.