某些机型微信小程序上传图片出错,但是app可以。
代码:
/**
* 上传图片到服务器
* [@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()
})
},