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

cordova-plugin-filepath: Unable to resolve filesystem path in android

Open thisisirfan opened this issue 5 years ago • 11 comments

Trying to upload image from ionic application via android/ios gallery. It's working perfectly fine on ios but throw error in android. It always throw following error while resolving native path in this.filePath.resolveNativePath(imagePath) method: {code: 0 ; message: "Unable to resolve filesystem path."}

Here is my code for uploading image:

var options = {
  quality: 60,
  targetWidth:900,
  sourceType: sourceType,
  saveToPhotoAlbum: false,
  correctOrientation: true
};
// Get the data of an image
this.camera.getPicture(options).then((imagePath) => {
  if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
    console.log('image path',imagePath)
    this.filePath.resolveNativePath(imagePath)
      .then(res => {
        let correctPath = res.substr(0, res.lastIndexOf('/') + 1).toString();
        let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.length).toString();
        this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
      }).catch(err=>{
        console.log('unable to resolve file path issue', err)
      });
  } else {
    var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
    var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
    console.log(currentName,correctPath)
    this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
  }
}, (err) => {
  console.log(err);
});

I have even tried using following code but no success:

window.FilePath.resolveNativePath(imagePath)
      .then(res => {
        let correctPath = res.substr(0, res.lastIndexOf('/') + 1).toString();
        let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.length).toString();
        this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
      }).catch(err=>{
        console.log('unable to resolve file path issue', err)
      });

Here are my plugin details:

<plugin name="cordova-plugin-camera" spec="^4.0.3" />
<plugin name="cordova-plugin-filepath" spec="^1.4.2" />

Ionic info

   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.1
Cordova:
   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : android 7.1.4
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.1, (and 15 other plugins)
System:
   Android SDK Tools : 25.2.4
   NodeJS            : v9.11.1
   npm               : 6.0.1 
   OS                : Windows 10

thisisirfan avatar Jan 23 '19 08:01 thisisirfan

update filepath plugin to the latest version which is 1.5.1

ionic cordova plugin rm cordova-plugin-filepath ionic cordova plugin add cordova-plugin-filepath@latest

If that doesn't work then it might be from the ionic webview plugin

PeterHdd avatar Jan 23 '19 08:01 PeterHdd

update filepath plugin to the latest version which is 1.5.1

ionic cordova plugin rm cordova-plugin-filepath ionic cordova plugin add cordova-plugin-filepath@latest

If that doesn't work then it might be from the ionic webview plugin

Thanks for responding, I've already tried with latest version but it still didn't work.

thisisirfan avatar Jan 23 '19 09:01 thisisirfan

Alright try the important section and tell me if it works or not.

As im also using the file path plugin to upload files to the server, and it worked with me.

PeterHdd avatar Jan 23 '19 09:01 PeterHdd

Alright try the important section and tell me if it works or not.

As im also using the file path plugin to upload files to the server, and it worked with me.

Ok following it

thisisirfan avatar Jan 23 '19 09:01 thisisirfan

Alright try the important section and tell me if it works or not. As im also using the file path plugin to upload files to the server, and it worked with me.

Ok following it

I have followed the https://github.com/PeterHdd/cordova-plugin-crypto-file#important steps and it result encrypt text rather than ionic page.

thisisirfan avatar Jan 23 '19 10:01 thisisirfan

Alright try the important section and tell me if it works or not. As im also using the file path plugin to upload files to the server, and it worked with me.

Ok following it

I have followed the https://github.com/PeterHdd/cordova-plugin-crypto-file#important steps and it result encrypt text rather than ionic page.

Ok i have compiled it again, now app run fine but image upload still return same error:

message: "Unable to resolve filesystem path.

thisisirfan avatar Jan 23 '19 10:01 thisisirfan

@PeterHdd It's seems like an android version issue, i just tested in android 5.1 version and it was working perfectly fine but not working on android 8.0 version

thisisirfan avatar Jan 23 '19 11:01 thisisirfan

@PeterHdd It's seems like an android version issue, i just tested in android 5.1 version and it was working perfectly fine but not working on android 8.0 version

Same issue. Anywhere exist a workaround? Thanks

UDTDR avatar Mar 05 '19 10:03 UDTDR

Same here!

noveweb avatar Nov 06 '19 18:11 noveweb

same issue here..

"cordova-plugin-filepath": "^1.5.8", "@ionic-native/file-path": "^5.29.0",

Any workarounds yet?

d3v53c avatar Nov 04 '20 13:11 d3v53c

any solution?

bhandaribhuminpfizer avatar Mar 18 '21 06:03 bhandaribhuminpfizer