收藏
回答

某些机型微信小程序上传图片出错,但是app可以。

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.uploadFile 微信安卓客户端 7.0.3 2.6.2


代码:

/**
* 上传图片到服务器
* @param filePath
*/
uploadFileToServer: async function(filePath) {
   const {address} = this.data;
   const {extData = {}} = this.properties;
   const formData = {...address, ...extData};
   const AuthenToken = await getCookie(COOKIE_KEY_TOKEN);
   const commHeader = await getCookie(COOKIE_KEY_COMM_HEADER);
   const url = baseUrl + uploadCertImg + "?" + Object.keys(formData).map(key => key + "=" + formData[key]).join("&");
   wx.uploadFile({
       url,
       filePath,
       name: 'file',
       header: {
           AuthenToken,
           ...commHeader,
           "Content-Type": "multipart/form-data;charset=UTF-8"
       },
       success: (res) => {
           const data = JSON.parse(res.data || "{}");
           const {code, data: imgData, status, exception, msg} = data;
           const {picUrl} = imgData;
           if (code !== 0) {
               this.uploadFail(msg);
           } else {
               this.changeImage(picUrl, imgData);
           }
       },
       fail: err => this.uploadFail((err || {}).errMsg),
       complete: () => this.hideLoading()
   })
},


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签