首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将图像从url保存到“资产”文件夹

如何将图像从url保存到“资产”文件夹
EN

Stack Overflow用户
提问于 2020-07-29 22:40:44
回答 1查看 2.3K关注 0票数 0

我正在使用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:

代码语言:javascript
复制
apiURL = 'my api url...';
 getDiarios() {
    const diarioArgs = {
      method: 'GET',
      mode: 'cors',
      headers: {
        'Content-Type': 'application/json' }
    };
    return this.http.get(this.apiURL, diarioArgs);
  }

然后我有一个函数,它调用服务并检索响应:

代码语言:javascript
复制
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")
    }
  }

如果有人能帮我,我新的离子和棱镜在一般情况下,所以任何建议都会有帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-30 05:16:36

“资产”文件夹仅在运行时读取。

您只能在设计期间存储文件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63163507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档