hiddentao / cordova-plugin-filepath

Resolve native file paths from content URLs for Cordova platforms
Apache License 2.0
66 stars 127 forks source link

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

Open thisisirfan opened 5 years ago

thisisirfan commented 5 years ago

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 (cordova-lib@8.1.1)
   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
PeterHdd commented 5 years ago

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

thisisirfan commented 5 years ago

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.

PeterHdd commented 5 years ago

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.

thisisirfan commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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

UDTDR commented 5 years ago

@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

noveweb commented 4 years ago

Same here!

d3v53c commented 3 years ago

same issue here..

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

Any workarounds yet?

bhandaribhuminpfizer commented 3 years ago

any solution?