Skip to content
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

@7.0.0 resolveLocalFileSystemURL a content uri get a FileError  #525

Closed
3 tasks done
lovelyelfpop opened this issue Jun 9, 2022 · 8 comments · Fixed by #534
Closed
3 tasks done

@7.0.0 resolveLocalFileSystemURL a content uri get a FileError  #525

lovelyelfpop opened this issue Jun 9, 2022 · 8 comments · Fixed by #534

Comments

@lovelyelfpop
Copy link

lovelyelfpop commented Jun 9, 2022

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

Cordova@11.0.0
Cordova-Android@10.1.2
cordova-plugin-file@7.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • 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);
grassick added a commit to mWater/cordova-plugin-file that referenced this issue Jul 21, 2022
@grassick
Copy link
Contributor

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.

@HarelM
Copy link

HarelM commented Aug 3, 2022

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

@grassick
Copy link
Contributor

grassick commented Aug 4, 2022

I've created a PR at #534

@HarelM
Copy link

HarelM commented Aug 4, 2022

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

@breautek
Copy link
Contributor

breautek commented Aug 7, 2022

Believe it's a regression of #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.

@brunolau
Copy link

brunolau commented Dec 9, 2022

Any ETA when this gets merged / fixed ?

angjelkom pushed a commit to angjelkom/cordova-plugin-file that referenced this issue Dec 13, 2022
angjelkom pushed a commit to angjelkom/cordova-plugin-file that referenced this issue Dec 13, 2022
veronicatc added a commit to veronicatc/cordova-plugin-file that referenced this issue Feb 2, 2023
@lovelyelfpop
Copy link
Author

When will this gets merged?

@mirko77
Copy link

mirko77 commented Mar 16, 2023

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

pinionpi added a commit to pinionpi/cordova-plugin-file that referenced this issue Apr 10, 2023
* origin/mWater/fix-issue-525:
  Revert indent
  Indent using spaces
  Correct indent
  Fix apache#525
@erisu erisu closed this as completed in #534 Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants