有大lao知道uniapp将图片保存手机相册相关问题吗
为什么uniapp的uni.downloadFile ()+ uni.saveImageToPhotosAlbum()方法保存不了后端接口返回的二维码地址吗 而我从百度上随便搜了个图片地址就可以保存到手机相册 很奇怪诶,下面是二维码地址和图片地址 图片地址可以保存
testUrl:"https://mobilecodec.alipay.com/show.htm?code=2ie124106hjuyfrkuzeauec"
// testUrl:"https://img0.baidu.com/it/u=1997330805,2252719449&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1699981200&t=395f6c1528a5f05920a8d2c8017920b1"
下面是完整代码
<template>
<view>
<image :src="testUrl" mode="" style="width: 400rpx;height: 400rpx;" @longpress="longPress(testUrl)"></image>
</view>
</template>
<script>
import {
showConfirm,
toast
} from '@/utils/common'
export default {
data() {
return {
testUrl:"https://mobilecodec.alipay.com/show.htm?code=2ie124106hjuyfrkuzeauec"
// testUrl:"https://img0.baidu.com/it/u=1997330805,2252719449&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1699981200&t=395f6c1528a5f05920a8d2c8017920b1"
}
},
methods: {
// 长按提示 保存图片
longPress(url){
console.log(url)
uni.showActionSheet({
itemList:['保存图片'],
success: (res) => {
this.savePhoto(url)
}
})
},
// 保存图片
savePhoto(url) {
console.log('url',url)
const that = this
uni.downloadFile({
url: url,
success: (res) => {
console.log('res',res)
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res2) {
console.log('res2',res2)
uni.hideLoading();
toast("已保存到系统相册")
}
})
}
}
});
},
}
}
</script>
<style>
</style>