API.file=function(url,fileName){
url = baseURL +'/v1/file/image?url='+ url;
let newPath=`${wx.env.USER_DATA_PATH}/${fileName}`;
const File= wx.getFileSystemManager();
return new Promise((resolve,error)=>{
wx.downloadFile({
url: url,
success (res) {
console.log('文件下载',res);
if (res.statusCode === 200) {
wx.saveFile({
tempFilePath: res.tempFilePath,
// filePath:wx.env.USER_DATA_PATH+'/'+fileName,
success(result){
console.log('2222222',result);
if (result.errMsg == 'saveFile:ok') {
resolve(result)
wx.showToast({
title: '文件保存成功!',
icon: 'success',
duration: 2000
})
console.log('文件保存路径为:',result.savedFilePath);
}else{
error()
wx.showToast({
title: '文件保存失败!',
icon: 'error',
duration: 2000
})
}
},
fail(){
error()
wx.showToast({
title: '文件保存失败!',
icon: 'error',
duration: 2000
})
if(fail){
fail(e);
}
}
})
}
},
fail:function(e){
error()
wx.showToast({
title: '文件下载失败!',
icon: 'error',
duration: 2000
})
if(fail){
fail(e);
}
}
})
})
}