我正在使用Ionic和Cordova一起开发我的第一个Android应用程序,我需要从REST中检索一个图像并将它存储在我的设备上,这样即使设备离线,我也可以使用它。
以下是im使用的当前版本:
离子:
离子CLI : 6.10.1 (C:\Users\agusd\AppData\Roaming\npm\node_modules@ionic\cli)离子框架:@离子/角质5.3.1 @角-devkit/构建-角度: 0.901.12 @角-devkit/原理图: 9.1.12 @角/cli: 9.1.12 @离子/角-工具包: 2.3.0
电容器:
电容器CLI : 2.4.0 @电容器/芯: 2.4.0
Cordova:
Cordova CLI : 9.0.0 ( Cordova -lib@9.0.1) Cordova平台: android 8.1.0 cordova Plugins :cordova-plugin-离子型-键盘2.2.0,cordova-plugin-离子型webview 4.2.1 (和其他4个插件)
我遵循的指南,为Ionic 3,但我无法使它工作在我目前的离子版本。
到目前为止,我已经成功地获得了包含URL的JSON对象,但我不知道如何下载该映像并将其存储到我的资产文件夹中。
我的代码是这样的:
api.service.ts:
apiURL = 'my api url...';
getDiarios() {
const diarioArgs = {
method: 'GET',
mode: 'cors',
headers: {
'Content-Type': 'application/json' }
};
return this.http.get(this.apiURL, diarioArgs);
}然后我有一个函数,它调用服务并检索响应:
data: any;
lastDiario: any;
lastID = 0;
loadLastDiario() {
try {
this.apiService.getDiarios().subscribe(
(data) => {
this.data = data;
for (const item of this.data.content) {
if (item.id > this.lastID) {
// I get the object with the largest id, which means is the last uploaded
this.lastID = item.id;
this.lastDiario = item;
}
}
console.log(this.lastDiario);
for (const item of this.lastDiario.archivos) {
// Here is where I need to save every item of "archivos" into my assets folder or any other
// Every item has an URL property that I can get through **this.lastDiario.archivos.url**
}
}
);
} catch (error) {
console.log("Couldn't connect to the service")
}
}如果有人能帮我,我新的离子和棱镜在一般情况下,所以任何建议都会有帮助!
发布于 2020-07-30 05:16:36
“资产”文件夹仅在运行时读取。
您只能在设计期间存储文件。
https://stackoverflow.com/questions/63163507
复制相似问题