某些机型微信小程序上传图片出错,但是app可以。
发布于 7 年前 作者 lei40 3390 次浏览 来自 官方Issues

代码:

/**
* 上传图片到服务器
* [@param](/user/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 回复

看错误提示建议检查下证书

回到顶部