1***@qq.com
1***@qq.com
  • 发布:2020-03-04 12:36
  • 更新:2020-12-11 09:48
  • 阅读:2494

uniapp ios APP 保存图片失败

分类:uni-app

uniapp ios APP 保存图片失败 图片文件路径已配置 但是后缀并不是图片文件的,不知道是不是这个问题

    //下载图片  
                uni.downloadFile({  
                    url: this.certificateUrl,  
                    success: res => {  
                        that.$forceUpdate();  
                        uni.hideLoading();  
                        if (res.statusCode === 200) {  
                            let path = res.tempFilePath;  
                            console.log(res, 'path');  
                            uni.saveImageToPhotosAlbum({  
                                filePath: path,  
                                success(res) {  
                                    uni.showToast({  
                                        title: '保存成功',  
                                        icon: 'none'  
                                    });  
                                },  
                                fail(err) {  
                                    console.log(err,'错误信息')  
                                uni.showToast({  
                                    title: '保存失败',  
                                    icon: 'none'  
                                });  
                                }  
                            });  

                        } else {  
                            uni.showToast({  
                                title: '保存失败',  
                                icon: 'none'  
                            });  
                        }  
                    },  
                    fail(err) {  
                        that.$forceUpdate();  
                        uni.hideLoading();  
                        console.log(err,'错误信息')  
                        uni.showToast({  
                            title: '保存失败',  
                            icon: 'none'  
                        });  
                    }  
                });
2020-03-04 12:36 负责人:无 分享
已邀请:
c***@126.com

c***@126.com

res.tempFilePath 的后缀有问题,我的处理方法是给uni.downloadFile 添加参数filePath
downloadFile() {
let that = this
let fileName = new Date().valueOf()
uni.downloadFile({
url: this.qrCodeUrl, // 图片地址
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.jpg',
success: function(res) {
// 图片保存到本地
that.saveCode(res)
}
})
},
saveCode(res) {
let that = this
if (res != '') {
uni.saveImageToPhotosAlbum({
filePath: res.filePath,
success: function() {
uni.showToast({
title: '二维码保存成功',
icon: 'success',
duration: 2000
})
},
fail() {
uni.showToast({
title: '保存二维码图片失败',
duration: 2000,
icon: 'none',
mask: true
})
}
})
} else {
uni.showToast({
title: '二维码图片不存在',
duration: 2000,
icon: 'none',
mask: true
})
}
}

1***@qq.com

1***@qq.com

您好,请问解决了吗

该问题目前已经被锁定, 无法添加新回复