【发布时间】:2021-02-07 21:11:39
【问题描述】:
我正在尝试从我的服务器下载文件,但我不断收到错误消息。被困了好几天。
HTML
<ion-button expand="block" (click)="download()">Download Files</ion-button>
TS
download() {
const url = 'http://ccoulter12.lampt.eeecs.qub.ac.uk/api/files/5d248f949c71e.pdf';
const path = this.file.dataDirectory;
const transfer = this.transfer.create();
transfer.download(url, path + 'myfile.pdf').then(entry => {
const url = entry.toURL();
if (this.platform.is('ios')) {
// this.document.viewDocument(url, 'application/pdf', {});
window.open(url);
} else {
this.fileOpener.open(url, 'application/pdf')
.then(() => console.log('File is opened'))
.catch(e => console.log('Error opening file', e));
}
});
}
【问题讨论】:
-
添加
.catch(error => { console.log(error); }以捕获来自transfer.download()..的错误 -
完成我已编辑以包含错误消息
标签: angular file download ionic4 file-transfer