首页 > 解决方案 > 如何从 axios 上传 2 个文件?

问题描述

最近,我需要一个脚本来使用 axios 将 2 个文件一起发布到我的烧瓶中。
我想使用 append 在我的 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", 
      })

而且我还想使用 request.files 接收烧瓶中的 2 个文件:

    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])

但是当我使用上传 2 个文件时,它告诉我一些错误:

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 0

有谁知道出了什么问题?

标签: javascriptvue.jsflaskaxios

解决方案


推荐阅读