cordova - Ionic 3:直接在`file:///android_asset/www/assets/i18n`中下载和替换文件
问题描述
我正在尝试通过下载并将其存储在应用程序目录中来直接更新翻译文件。下面是我下载和替换文件的代码,
private downloadLanguageFile(url: string, lang: string) {
const appDir = this.file.applicationDirectory;
let promise = this.http.get(url, {responseType: 'blob'}).toPromise();
promise.then((downloadedFile: any) => {
this.file.writeFile(appDir, `${lang}.json`, downloadedFile, {replace: true})
.then((data) => {
console.log(data);
}, (error) => {
console.log("error writing file", error);
})
}, (error) => {
console.log("Download language file failed", error);
});
return promise;
}
但不是将文件保存在该目录中,而是抛出此错误:
FileError {代码:1,消息:“NOT_FOUND_ERR”} 代码:1 消息:
“NOT_FOUND_ERR”
原型:对象
当我将文件目录更改为 dataDirectory 时,代码运行良好。关于我做错了什么的任何建议?提前致谢。
注意:允许将文件和目录从复制applicationDirectory
到任何其他目录,但不允许反向操作。
解决方案
推荐阅读
- javascript - 收到警告“警告:列表中的每个孩子都应该有一个唯一的“关键”道具。” 当我的组件渲染时
- string - TypeScript > 4.1 固定长度字符串文字类型
- r - order.terms 不会重新排序 sjPlot 的 plot_model 中的术语
- docker - 如何防止 Docker 在执行 RUN 命令时删除中间容器?
- amazon-web-services - 向用户添加 AWS 权限
- reactjs - React.js 中的重父化
- c++ - 使用 SFINAE 将 struct 的引用作为函数模板中的参数转发
- reactjs - 如何在 React 17 中将字符串转换为 JSX
- f# - 带有 Suave 和 Fable.Remoting 的 MissingMethodException
- view - CRM 动态。为适当的安全角色设置默认视图