cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

@7.0.0 resolveLocalFileSystemURL a content uri get a FileError 

Open lovelyelfpop opened this issue 2 years ago • 5 comments

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);

lovelyelfpop avatar Jun 09 '22 09:06 lovelyelfpop

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 avatar Jul 21 '22 00:07 grassick

@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?

HarelM avatar Aug 03 '22 10:08 HarelM

I've created a PR at https://github.com/apache/cordova-plugin-file/pull/534

grassick avatar Aug 04 '22 14:08 grassick

Yea, thanks! Saw that only after posting here...

HarelM avatar Aug 04 '22 14:08 HarelM

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.

breautek avatar Aug 07 '22 01:08 breautek

Any ETA when this gets merged / fixed ?

brunolau avatar Dec 09 '22 14:12 brunolau

When will this gets merged?

lovelyelfpop avatar Feb 20 '23 03:02 lovelyelfpop

@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.

mirko77 avatar Mar 16 '23 16:03 mirko77