uniapp之文件保存
uniapp之文件保存
文件保存分几种情况:
1.网络文件保存:
使用uni.downloadFile创建临时文件地址,然后使用uni.saveFile保存
uni.downloadFile({ //下载
url: path,
success: (res) => {
if (res.statusCode == 200) {
uni.saveFile({
tempFilePath: res.tempFilePath,
success: (res) => {
this.aaa = res
console.log(res)
},
fail: (err) => {
this.aaa = err
console.log(err)
}
})
}
}
})
2.base64保存
使用image-tools组件的base64ToPath方法,将base64转为临时文件地址,然后使用uni.saveFile保存
base64ToPath(base64Obj)
.then(path => {
console.log(path)
uni.saveFile({
tempFilePath: path,
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})
3.uni.saveFile保存,文件会被保存在_doc/...地址下,手机上无法查看。
4.将图片保存到相册:
uni.saveImageToPhotosAlbum({ filePath: path, success: function() { uni.showToast({ title: "保存成功", icon: "none" }); }, fail: function() { uni.showToast({ title: "保存失败,请稍后重试", icon: "none" }); } });
5.使用plus,未测试
钻研不易,转载请注明出处。。。。。。

浙公网安备 33010602011771号