首页 > 解决方案 > cordova-plugin-file 在 ios 上不起作用,无法将我捕获的图像保存在 Document 目录中

问题描述

我正在尝试借助 Cordova File 插件将捕获的图像保存在 Document 目录中。

下面是我将文件写入 Document 目录的代码:

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);  
    })  
  }  

但它不起作用,并且它没有在控制台上抛出任何错误。

知道我的代码出了什么问题还是我遗漏了什么?

在这个问题上指导我。

提前致谢!

标签: iosionic3cordova-plugin-file

解决方案


我找到了上述问题的解决方案。

这是因为插件版本"@ionic-native/core".

所以我的"@ionic-native/core"版本是"4.17.0"并且我安装了"@ionic-native/file": "^5.14.0"

所以要么我们需要升级@Ionic-native/core版本,要么降级文件插件版本。

所以我决定降级 Ionic File 插件版本。

完成此操作后,它按预期工作。

我从这个问题中学到了什么?

Ans:仅使用带有核心框架的插件支持版本,否则它将无法工作,也不会抛出任何错误。

注意:在安装任何插件时不要忽略任何登录终端的警告。

我在这里发布,以便其他人可以发现它有帮助。

谢谢大家关注我的问题。


推荐阅读