【发布时间】:2020-10-29 01:46:27
【问题描述】:
我正在尝试使用我的 ionic 应用程序下载一个文件,但它不起作用,该文件是一个视频文件,我想在下载时显示一个进度条,它的工作原理是当用户点击下载时,它会检查目录AppName是否存在,它不会创建目录,然后下载目录中的文件。
这是我的代码
download() {
this.chkmkDir().then(async ()=>{
const fileTransfer: FileTransferObject = this.fileTransfer.create();
this.storageDirectory = `${this.file.dataDirectory}${api.AppName}/`;
fileTransfer.onProgress((progressEvent)=>this.progress=Math.round((progressEvent.loaded / progressEvent.total) * 100))
let fileName=await this.service.getFileName('mp4')
var URL = encodeURI('test.mp4');
fileTransfer.download(URL,`${this.storageDirectory}${fileName}`, true)
})
}
chkmkDir(){
return new Promise((resolve, reject)=>{
this.file.checkDir(this.file.dataDirectory, api.AppName).then(res=>resolve()
).catch(err => {
this.file.createDir(this.file.dataDirectory, api.AppName,false).then(res =>resolve())
.catch(err=>reject(JSON.stringify(err)));
});
})
}
请问我做错了什么,我在控制台中收到此错误
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined TypeError: Cannot read property 'then' of undefined
【问题讨论】:
标签: ionic-framework