- wx.uploadFile上传jpg, MIME错误, 不能传到微信优惠券
wx.uploadFile在上传jpg图片的时候, content-type设置成image/jpg. 这个在MIME的表里是没有的, 微信的优惠券的服务器拒绝上传, 应该设置成image/jpeg https://developers.weixin.qq.com/blogdetail?action=get_post_info&lang=zh_CN&docid=becd925aa7a3b4b1c303cccb9656b86d
2017-12-11 - wx.uploadFile接口上传jpg图片, content-type类型错误
出现的问题: 通过wx.chooseImage获取的图片(压缩或原图), 如果图片为jpg格式, 通过wx.uploadFile上传的图片的content-type类型为image/jpg, 正确类型是image/jpeg . 复现的步骤: 选择图片, 图片是压缩的或者是jpg原图 [代码]wx.chooseImage({[代码][代码] count: 1, [代码][代码] sizeType: [[代码][代码]'original'[代码][代码], [代码][代码]'compressed'[代码][代码]], [代码][代码] sourceType: [[代码][代码]'album'[代码][代码], [代码][代码]'camera'[代码][代码]],[代码][代码] success: [代码][代码]function[代码] [代码](res) {[代码][代码] var[代码] [代码]tempFilePaths = res.tempFilePaths[代码][代码] that.setData({ cover: tempFilePaths})[代码][代码] }[代码][代码] })[代码] 上传图片, 后台是微信优惠券的图片服务器 [代码][代码] var path = this.data.cover [代码]wx.uploadFile({[代码] [代码] [代码][代码]url: [代码][代码]''[代码][代码],[代码][代码] [代码][代码]filePath: path[0],[代码][代码] [代码][代码]name: [代码][代码]'image'[代码][代码],[代码][代码] [代码][代码]header: {[代码][代码] [代码][代码]"Content-Type"[代码][代码]: [代码][代码]"multipart/form-data;"[代码][代码],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]var[代码] [代码]data = res.data[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] 抓包发现, 凡是jpg的图片的content-type都是image/jpg, 一般服务端都是以image/jpeg来处理jpg图片的, 导致图片上传失败
2017-12-07