我知道此链接:https : //cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#where-to-store-files
但我想将文件保存在下载目录中。是否可以使用Ionic将文件保存在任何路径中?如果是这样,请分享示例。
这是代码:
downloadImage(image) {
this.platform.ready().then(() => {
const fileTransfer: TransferObject = this.transfer.create();
const imageLocation = `${cordova.file.applicationDirectory}www/assets/img/${image}`;
fileTransfer.download(imageLocation, cordova.file.externalDataDirectory + image).then((entry) => {
const alertSuccess = this.alertCtrl.create({
title: `Download Succeeded!`,
subTitle: `${image} was successfully downloaded to: ${entry.toURL()}`,
buttons: ['Ok']
});
alertSuccess.present();
}, (error) => {
const alertFailure = this.alertCtrl.create({
title: `Download Failed!`,
subTitle: `${image} was not successfully downloaded. Error code: ${error.code}`,
buttons: ['Ok']
});
alertFailure.present();
});
});
}
Run Code Online (Sandbox Code Playgroud)
基本上,我想将文件保存在用户可见的位置。
所以有这个原始 npm 包的 repo:https : //github.com/twinssbc/Ionic2-Calendar。
我想在我的项目中使用它的 fork,它不作为 npm 包存在:https : //github.com/twinssbc/Ionic2-Calendar/tree/24feacfb29102ec61d6814281867e356fb1a9ee0。
我希望能够在我的 Ionic3 项目中使用这个 fork,因为我使用原始包。我如何实现这一目标?我应该用 fork 创建我自己的 npm 包还是有一些更简单的方法?