手机上使用wx.downloadFile下载oss上的.png图片,返回是.bin格式的文件,到时后续用wx.saveImageToPhotosAlbum保存图片失败,报{errMsg: "saveImageToPhotosAlbum:fail invalid file type"},但是在开发工具上可以直接返回png格式图片,可以保存。
如下为用wx.downloadFile请求和返回的结果。
wx.downloadFile({
success(res) {
if (res.statusCode === 200) {
console.log(res)
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
console.log(res)
wx.showToast({
icon: 'none',
title: "图片已保存"
})
},
fail(res){
console.log(res)
}
})
}
}
})
返回结果
{tempFilePath: "wxfile://tmp_54d93ed93a853a3a9765337741943c492df65fcd1db83a0a.bin", header: {…}, statusCode: 200, errMsg: "downloadFile:ok"}
errMsg: "downloadFile:ok"
header:
Accept-Ranges: "bytes"
Connection: "keep-alive"
Content-Disposition: "attachment;filename=gm.png"
Content-Length: "103837"
Content-MD5: "T4RW3zvQtapK4rYXVczxJA=="
Content-Type: "application/octet-stream"
Date: "Mon, 14 Oct 2019 01:12:50 GMT"
ETag: ""4F8456DF3BD0B5AA4AE2B61755CCF124""
Last-Modified: "Sun, 13 Oct 2019 14:30:55 GMT"
Server: "AliyunOSS"
X-Android-Received-Millis: "1571015568965"
X-Android-Response-Source: "NETWORK 200"
X-Android-Selected-Protocol: "http/1.1"
X-Android-Sent-Millis: "1571015568954"
x-oss-hash-crc64ecma: "13627780087634526589"
x-oss-object-type: "Normal"
x-oss-request-id: "5DA3CB929ACC073532C38DAE"
x-oss-server-time: "2"
x-oss-storage-class: "Standard"
__proto__: Object
statusCode: 200
tempFilePath: "wxfile://tmp_54d93ed93a853a3a9765337741943c492df65fcd1db83a0a.bin"
__proto__: Object
建议服务器返回content-type
请问楼主解决了么
请问你解决了吗?
麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
问题补充:iphone没问题 安卓的才有这个问题