首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用fileTransfer下载Ionic 4

使用fileTransfer下载Ionic 4
EN

Stack Overflow用户
提问于 2019-03-08 16:58:13
回答 1查看 4.3K关注 0票数 3
代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { ModalController, Platform } from '@ionic/angular';
import { PushdataService } from '../pushdata.service';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file/ngx';

@Component({
  selector: 'app-modalquotes',
  templateUrl: './modalquotes.page.html',
  styleUrls: ['./modalquotes.page.scss'],
})
export class ModalquotesPage implements OnInit {

  public storageDirectory:any;

  constructor(private transfer: FileTransfer, private file: File, private modalCtrl: ModalController, public pushdata: PushdataService) {
  }


  downloadme() {

    const fileTransfer: FileTransferObject = this.transfer.create();
      this.storageDirectory = this.file.externalRootDirectory + 'Download/';

      const url = "https://xxxxx.com/server_api/asset/quotes/test.jpeg";
      fileTransfer.download(url,this.storageDirectory + "test.jpeg", true).then(
          (entry) => {
            alert('Berhasil download dan tersimpan di : ' + this.storageDirectory + "test.jpeg");
          }, (error) => {
            alert('gagal : ' + JSON.stringify(error));
          });

  }


  ngOnInit() {
  }

}

这是我的代码page.ts,但下载结果是"Permitte page.ts“。请帮帮我,我已经尝试了很多,除了一些错误。这只适用于"this.file.externalApplicationStorageDirectory",但只能从根文件夹应用程序下载文件。但我希望将此图像下载到文件夹下载。

EN

回答 1

Stack Overflow用户

发布于 2019-03-08 17:39:50

首先,externalRootDirectory属性用于将文件存储到外部存储器,如SD卡。

因此,我建议您更改以下代码行:

this.storageDirectory = this.file.externalRootDirectory + 'Download/';

代码语言:javascript
复制
          TO

this.storageDirectory = 'Download/';

这会将您的文件下载到Downloads文件夹

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

https://stackoverflow.com/questions/55059722

复制
相关文章

相似问题

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