【发布时间】:2017-06-27 15:23:59
【问题描述】:
假设我有一个 JSON 对象,其中包含来自 Web API 的用户个人资料,包括名字、姓氏、...和 profileUrl。我已经使用 Sqlite 保存了文本数据,现在我想将这些图像保存在本机存储中,并将文件路径放入 sqlite 数据库中,替换 profileUrl。
【问题讨论】:
假设我有一个 JSON 对象,其中包含来自 Web API 的用户个人资料,包括名字、姓氏、...和 profileUrl。我已经使用 Sqlite 保存了文本数据,现在我想将这些图像保存在本机存储中,并将文件路径放入 sqlite 数据库中,替换 profileUrl。
【问题讨论】:
您可以为此使用cordova-plugin-file-transfer。甚至还有一个可用的 Ionic Native 包装器:https://ionicframework.com/docs/native/transfer/
例子:
download() {
const url = 'http://www.example.com/file.pdf';
fileTransfer.download(url, this.file.dataDirectory + 'file.pdf').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}
【讨论】: