ios - 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);
})
}
但它不起作用,并且它没有在控制台上抛出任何错误。
知道我的代码出了什么问题还是我遗漏了什么?
在这个问题上指导我。
提前致谢!
解决方案
我找到了上述问题的解决方案。
这是因为插件版本与"@ionic-native/core"
.
所以我的"@ionic-native/core"
版本是"4.17.0"
并且我安装了"@ionic-native/file": "^5.14.0"
所以要么我们需要升级@Ionic-native/core
版本,要么降级文件插件版本。
所以我决定降级 Ionic File 插件版本。
完成此操作后,它按预期工作。
我从这个问题中学到了什么?
Ans:仅使用带有核心框架的插件支持版本,否则它将无法工作,也不会抛出任何错误。
注意:在安装任何插件时不要忽略任何登录终端的警告。
我在这里发布,以便其他人可以发现它有帮助。
谢谢大家关注我的问题。
推荐阅读
- c - 当我尝试换行时,它没有正确插入
- javascript - Dynamobd 错误:即使我输入了实际条目 ID,扫描结果也不会过滤到 HASH
- php - 你能在 PHP 中为 Firebase 获得一个短暂的 OAuth 2.0 访问令牌吗?
- c# - 如何将 IndexOf 与来自 mongodb c# 的 Builders 过滤器一起使用
- java - 当人脸位于所需帧中时,如何实时启动 ML Kit 人脸检测
- angular - Http调用在角度通用中进行了两次
- php - 将 HTML 标记添加到所见即所得编辑器
- java - 重新获取 BufferedImage 的先前 Graphics2D 实例
- wordpress - 如何在模板 Wordpress 中插入标题属性
- android - 实现 webview 以使用 vimeo 嵌入链接