[Android] content:// to file://storage does not get resolve

When you take pdf anyother file from download you get URI with content://. So in order to resolve i use this package to get file URI path https://www.npmjs.com/package/cordova-plugin-filepath

It returns error code: 1 // not found

const options: CameraOptions = {
          quality: 50,
          destinationType: this._camera.DestinationType.FILE_URI,
          mediaType: this._camera.MediaType.ALLMEDIA,
          sourceType: this._camera.PictureSourceType.SAVEDPHOTOALBUM,
          saveToPhotoAlbum: false,
        };
 if (file.indexOf("content://") > -1) {
          console.log("content //", file);
          window.FilePath.resolveNativePath(file, (success) => {
            console.log(success, "content");
            window.resolveLocalFileSystemURL(success, (fileEntry) => {
              console.log(fileEntry, "fileEntry");
              fileEntry.file((finalFile) => {
                console.log(finalFile, "resolve");
                resolve(finalFile);
              });
            });
          });
        }

chrome://inspect
image

If this is with cordova and the ionic webview plugin is installed, you’ll need to convert the file://protocol

This is ionic 3 project with webview version 1.2.1 there i am sure we dont convert anything am i correct since it serve with file protocol. Where as with latest webview we use convertFileSrc then blob with fetch().

I don’t have any issue if i move the downloaded file somewhere in other folder it is working fine. As you can see cordova camera what it returns content://com. blah blah/download then we use filePath pkg.

Same error i am getting if i use combination with filechooser + filepath pkg.

anyother workaround that can i apply here ?

Not 100% sure to be honest. I have not been using cordova for some time now.

Repo to reproduce: https://github.com/indraraj26/cordova-camera-fast-click/tree/content-file-path
Branch: content-file-path
On Android 10 it returns code 1 error i.e file not found

Android 7 vs Android 10

Google don’t want people to convert content urls to file urls for privacy reasons, because content urls don’t belong to your app and they just make it harder on every release.

As workaround you can enable legacy storage, that will work for Android 10, but not for 11 and newer.
For enabling legacy storage add this to the application tag in the AndroidManifest.xml

android:requestLegacyExternalStorage="true"

1 Like

Thank you for quick reply, If you check above repo you will see i am already using the android:requestLegacyExternalStorage="true"

Can you test my repo in your android 10

step to reproduce:

  1. open google chrome and search for download dummy pdf and download that file.
  2. then open this app and select that downloaded dummy pdf file