iosionic3cordova-plugin-file

cordova-plugin-file is not working on ios and unable to save my captured image in Document directory


I am trying to save my captured Image in Document directory with the help of Cordova File plugin.

Below is my code to write file into Document directory:

saveFile(){
    console.log("saveFile start");
    this.filename = "photo_1234.jpeg"; 
    console.log('filename:',this.filename);
    this.platform.ready().then(() => { 
      this.filePath = this.file.documentsDirectory;       
      console.log('filePath:',this.filePath);
      this.writeFile(this.selectedImage,"MyPhotos", this.filename, this.filePath);
    }); 
  }


//here is the method is used to write a file in storage  
  public writeFile(base64Data: any, folderName: string, fileName: any, filePath: any) { 
    console.log("writeFile start");
    let contentType = this.getContentType(base64Data);  
    let DataBlob = this.base64toBlob(base64Data, contentType);  
    // here iam mentioned this line this.file.externalRootDirectory is a native pre-defined file path storage. You can change a file path whatever pre-defined method.  
    this.file.writeFile(filePath, fileName, DataBlob, contentType).then((success) => {  
        console.log("File Writed Successfully", success);  
        this.saveData();
    }).catch((err) => {  
        console.log("Error Occured While Writing File", err);  
    })  
  }  

But it's not working and event it's not throwing any error on console.

Any idea what's going wrong with my code or am I missing something?

Guide me on this issue.

Thanks in advance!


Solution

  • I found the solution to the above issue.

    It's because of the plugin version miss-match with "@ionic-native/core".

    So my "@ionic-native/core" version was "4.17.0" and I installed "@ionic-native/file": "^5.14.0"

    So either we need to upgrade @Ionic-native/core version or downgrade file plugin version.

    So I decided to downgrade Ionic File plugin version.

    After doing this it's working as expected.

    What I learned from this issue?

    Ans: Use only supported version of the plugin with core frameworks otherwise, it will not work and also will not throw any error.

    Note: Don't ignore any warning logged in terminal while installing any plugin.

    I posted here so that others can find it helpful.

    Thanks, everyone for looking into my issue.