在小程序端,.js文件中,使用以下代码下载文件
wx.showLoading({
title: '下载中',
});
console.log("下载文件:",fileId);
wx.cloud.downloadFile({
fileID: fileId,
timeout: 30,
success: (result) => {
console.log("下载成功",result.tempFilePath);
},
fail: (res) => {
console.log("下载失败:",res);
wx.showToast({
title: res.errMsg,
icon:'error'
});
},
complete: (res) => {
wx.hideLoading();
},
})
1结果:模拟器下载文件成功。
真机预览(开发版)和体验版本,都是提示:“cloud.downloadFile:fail undefined . downloadFile:fail timeout"
{message: "cloud.downloadFile:fail undefined . downloadFile:fail timeout", errCode: -1, errMsg: "cloud.downloadFile:fail undefined . downloadFile:fail timeout", line: 1, column: 234894, …}column: 234894errCode: -1errMsg: "cloud.downloadFile:fail undefined . downloadFile:fail timeout"line: 1message: "cloud.downloadFile:fail undefined . downloadFile:fail timeout"sourceURL: "https://lib/WACloud.js"stack: "R@https://lib/WACloud.js:1:234894↵@https://lib/WACloud.js:1:311533↵t@https://lib/WACloud.js:1:375↵u@https://lib/WACloud.js:1:623↵q@https://lib/WASubContext.js:1:70977↵@https://lib/WASubContext.js:1:71199↵C@https://lib/WASubContext.js:1:40676↵@https://lib/WASubContext.js:1:54498↵I@https://lib/WASubContext.js:1:54267↵@https://lib/WASubContext.js:1:54305↵f@https://lib/WASubContext.js:1:163627↵@https://lib/WASubContext.js:1:126859↵@https://lib/WASubContext.js:1:158959↵p@https://lib/WAServiceMainContext.js:1:399727↵@https://lib/WAServiceMainContext.js:1:387729↵_onNativeTimer@↵global code@"
以上错误提示的意思是,入参timeout这个undefined,去掉这个参数就成功了。