Recently, I need to have a script to use axios post 2 files together to my flask.
I want to use append to create a file[] in my vue.
let formData = new FormData();
formData.append('files',this.file1);
formData.append('files',this.file2);
axios({
method: "post",
data:formData,
headers: {
'Content-Type': "multipart/form-data",
},
url: "http://127.0.0.1:5000/getPic",
responseType: "arraybuffer",
})
And I also want to use request.files to receive the 2 files in my flask:
files=[]
for i in range(len(request.files)):
{files.append(request.files[i])}
file_len =len(files)
if(file_len == 0):
return "未上传文件"
if(file_len == 1):
return "只上传了一个文件"
for i in file_len:
print (files[i].filename)
file1 = Image.open(files[0])
But when I use upload the 2 files it tell me something wrong:
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 0
Does anyone know what's wrong?