let data = {
"type": "jpg",
"spec": "1",
"bk": "blue",
"beauty_degree": 1.5
}
data.photo = base64Data;
wx.uploadFile({
url: 'https://www.pudding233.com/api/data.php', //后端接口
filePath: tempFilePaths[0],
method: 'POST',
name: 'file',
header: {
"Content-Type": "application/json"
},
// header: { 'Content-Type': 'multipart/form-data' },
formData: JSON.stringify(data),
success: function (res) {
wx.hideLoading({
success: (res) => {},
});
if (res.statusCode !== 200) {
wx.showModal({
title: '提示',
content: '上传失败',
showCancel: false
});
return;
} else {
console.log(res.data);
wx.navigateTo({
url: "../imgDetail/imgDetail?img=" + res.data,
events: {},
success: function (res) {}
})
}
},
fail(e) {
wx.showModal({
title: '提示',
content: '上传失败',
showCancel: false
});
},
complete() {
wx.hideToast(); //隐藏Toast
}
})
formData 为什么要字符串?它是个Object啊。不看文档吗
不要设置Content-Type