我正在尝试借助 Cordova 文件插件将捕获的图像保存在文档目录中。
下面是我将文件写入文档目录的代码:
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);
})
}
但它不起作用,并且它没有在控制台上抛出任何错误。
知道我的代码出了什么问题或者我遗漏了什么吗?
指导我解决这个问题。
提前致谢!
最佳答案
我找到了上述问题的解决方案。
这是因为插件版本不匹配与“@ionic-native/core”
。
所以我的 "@ionic-native/core"
版本是 "4.17.0"
并且我安装了 "@ionic-native/file": "^5.14.0"
所以我们要么需要升级@Ionic-native/core
版本,要么降级文件插件版本。
所以我决定降级 Ionic File 插件版本。
完成此操作后,它会按预期工作。
我从这个问题中学到了什么?
答:仅使用具有核心框架的插件受支持的版本,否则它将无法工作,也不会抛出任何错误。
Note: Don't ignore any warning logged in terminal while installing any plugin.
我发布在这里是为了其他人可以发现它有帮助。
谢谢大家调查我的问题。
关于ios - cordova-plugin-file 在 ios 上不起作用,无法将捕获的图像保存在文档目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57951696/