swan.downloadFile
Object object
success 返回参数说明 :
- Android
- iOS
扫码体验
请使用百度APP扫码
代码示例1 :
- 在 js 文件中
- 在 js 文件中
data: { },
downloadFile() {
url: 'https://smartprogram.baidu.com/docs/img/file-simple.pdf',
header: {
'content-type': 'application/json'
},
filePath: 'bdfile://usr/办理指南文档.pdf',
success: res => {
console.log(res);
let filePath = res.filePath;
title: '文件下载完成',
content: '是否需要打开?',
confirmText: '打开',
success: res => {
if (res.confirm) {
swan.openDocument({
filePath: filePath,
fileType: 'pdf',
this.toast('打开失败');
}
}
}
});
},
fail: err => {
this.toast('下载文件失败');
},
complete: () => {
swan.hideToast();
}
});
});
返回值:
- 文件的临时路径,在智能小程序本次启动期间可以正常使用,如需持久保存,需再主动调用 swan.saveFile,才能在智能小程序下次启动时访问得到;
- 下载最大限制10MB。