[问题求助]
Internet如何post一个headers为multipart/form-data的请求
用<aui-file-upload>上传组件选择了文件,给http-request属性绑定了事件,在事件中有formdata
调用HWH5.fetchInternet后, 在network中看body并不是FormData而是RequestPayload
/** 自定义上传请求 用于覆盖默认的上传行为 */
customizeUploadRequest(data) {
let fileData = data.file;
let actionData = data.action;
let myFormData = new FormData();
myFormData.append('object', fileData);
myFormData.append('dir', '');
HWH5.fetchInternet(actionData, {
// 请求方法
method: 'post',
headers: {
'Content-Type': 'multipart/form-data'
},
body: myFormData
})
.then(res => {
res.json().then(reply => {
console.log('上传请求结果: ', reply);
this.textData = JSON.stringify(reply);
});
})
.catch(error => {
console.log('请求异常', error);
this.textData = JSON.stringify(error);
});
} // func end