when uploading a file using upload in element, 400 errors are always reported. How to add parameters to this file + file and finally request the backend API to upload excel?
the following is my code. The background has always said that I passed the file but did not receive the parameters:
this is my html code:
<el-upload
class="image-uploader"
:multiple="false"
:auto-upload="true"
list-type="text"
:show-file-list="true"
:before-upload="beforeUpload"
:drag="true"
action="application/x-xls,"
:limit="1"
:on-exceed="handleExceed"
:http-request="importExcel" >
<el-button type="warning" ></el-button>
</el-upload>
:
//
beforeUpload (file) {
// console.log("beforeUpload")
console.log(file.type)
const isText = file.type === "application/vnd.ms-excel,.csv,text/plain"
const isTextComputer = file.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
return (isText | isTextComputer)
},
//
handleExceed (files, fileList) {
console.log(` 1 `);
},
importExcel(item){
const fileObj = item.file
const form = new FormData();
form.append("file", fileObj);
//console.log(item);
api.ImportFileRequest(Url.commodity.impoGood,{excel:form})
.then((res) => {
console.log(res);
},(response) => {
alert("");
}).catch(error => console.log(error));
},
is there any great god who can ask for advice and help solve the problem