Ionic 4下载使用fileTransfer

3
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,但下载结果显示“Permission Denied”。请帮助我,我已经尝试了很多方法,但仍然有错误。它只适用于"this.file.externalApplicationStorageDirectory",但文件下载只能从根文件夹apps中进行。但我想将这个图像下载到Download文件夹中。
1个回答

0
首先,externalRootDirectory 属性用于将文件存储到外部存储设备,例如 SD 卡。
因此,我建议您更改以下代码行:
this.storageDirectory = this.file.externalRootDirectory + 'Download/';
          TO

this.storageDirectory = 'Download/';

这将会把你的文件下载到“下载”文件夹中


目录未找到。 - Andy Ajhis Ramadhan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接