cordova-plugin-filepath
cordova-plugin-filepath copied to clipboard
[Android] content:// to file://storage does not get resolve
Bug Report
Problem
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
What is expected to happen?
It should resolve and return file detail
What does actually happen?
It returns error code: 1 // not found
Information
chrome://inspect
Command or Code
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);
});
});
});
}
Environment, Platform, Device
All Android version i think so btw currently i am testing on Android 10
Version information
Cordova CLI : 10.0.0 Cordova Platforms : android 9.0.0
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
In your Android Manifest, add this android:requestLegacyExternalStorage="true"
in the application tag.
Hi, It is already in place 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
Issue Thread on cordova plugin file: https://github.com/apache/cordova-plugin-file/issues/443
Here is what I did to solve my Android 10 problems, similar to yours:
- Android manifest: add the request Legacy External Storage true
- Before opening a file, I had to ask for permission, and I used Ionic Diagnostic plugin for this:
this.diagnostic.requestExternalStorageAuthorization().then((permission) => console.log('permission storage asked' + permission));