cordova-plugin-file
cordova-plugin-file copied to clipboard
@7.0.0 resolveLocalFileSystemURL a content uri get a FileError
Bug Report
Problem
resolveLocalFileSystemURL a content uri get FileError
What is expected to happen?
const uri = 'content://com.android.providers.media.documents/document/image%3A189210';
// or
// const uri = 'https://localhost/__cdvfile_content__/com.android.providers.media.documents/document/image%3A189210';
window.resolveLocalFileSystemURL(uri, function (fileEntry) {
console.log(fileEntry);
}, function(err) {
console.log(err)
});
It got a FileError (code 1, not found)
What does actually happen?
It should log the fileEntry in the console
Information
Environment, Platform, Device
Redmi K30 pro, Android 11
Version information
[email protected] [email protected] [email protected]
Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Reason
The code below inside function toNativeUri
in org\apache\cordova\file\ContentFilesystem.java
String authorityAndPath = inputURL.uri.getEncodedPath().substring(this.name.length() + 2);
got e_content__/com.android.providers.media.documents/document/image%3A189210
It should be
com.android.providers.media.documents/document/image%3A189210
The right code is:
String encodedPath = inputURL.uri.getEncodedPath();
String authorityAndPath = encodedPath.substring(encodedPath.indexOf(this.name) + 1 + this.name.length() + 2);
I've implemented this change here: https://github.com/mWater/cordova-plugin-file.git#fix-issue-525 so feel free to use this until this gets fixed.
I started to make a pull request, but the overhead to do so was too high (run tests, without clear instructions in README, etc). If someone else would like to, please go ahead. This is a pretty serious bug.
@grassick I suggest to open a PR, I agree that this is a serious bug. I'm surprised there isn't a test to check that toNativeUrl
and toLocalUrl
are symmetric - i.e. that you can create a situation where this basically fails.
If there is a PR then someone can help pushing it to be merged by helping out with the tests.
In any way, thanks for sharing your solution!
I also guess that reverting to version 6.x will also solve this, right?
I've created a PR at https://github.com/apache/cordova-plugin-file/pull/534
Yea, thanks! Saw that only after posting here...
Believe it's a regression of https://github.com/apache/cordova-plugin-file/pull/513 but not 100% sure. PR doesn't describe changes to content://
scheme specifically but I believe any scheme other than the http/https scheme has issues when using the WebViewAssetLoader.
PR looks good though.
Any ETA when this gets merged / fixed ?
When will this gets merged?
@grassick I have been trying your fork and it works.
However, a few users reported issues when using Solid Explorer to browse files on the device.
So when trying to resolve a URL like content://pl.solidexplorer2.files/storage/emulated/0/Download/ORARI-NUOTO-LIBERO-dal-13-al-18-settembre-2022.pdf
, error 1 is still returned. Any ideas? Any URL returned by Solid Explorer fails with error 1.