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文件夹中。