title: Python Upload Multiple Files with POST API - value error "Expected UploadFile, received: <class str>"
body: <p>I tried to upload multiple files using FastAPI.
  This is server's code.</p>
  <pre><code>@app.post('/img_multi_up')
  def img_multi_up(
      set_name: str = Form(...),
      n_index: int = Form(...),
      files: List[UploadFile] = File(...),
      ):
      ...
  </code></pre>
  <p>`</p>
  <p>The test on FastAPI docs web page is successful.
  (this is generated curl command.)</p>
  <pre><code>curl -X 'POST' \
    'http://.../img_multi_up' \
    -H 'accept: application/json' \
    -H 'Content-Type: multipart/form-data' \
    -F 'set_name=test' \
    -F 'n_index=4' \
    -F 'files=@t0.jpg;type=image/jpeg' \
    -F 'files=@t1.jpg;type=image/jpeg' \
    -F 'files=@t2.jpg;type=image/jpeg' \
    -F 'files=@t3.jpg;type=image/jpeg'
  </code></pre>
  <p>And then I tried to upload 4 files with below code.</p>
  <pre><code>set_name = 'test'
  n_index = 4
  fis = ['t0.jpg', 't1.jpg', 't2.jpg', 't3.jpg']
  files = {fi:open(fi,'rb') for fi in fis}
  bd = {'set_name':set_name, 'n_index':n_index, 'files':files}
  resp = requests.post(url,bd)
  </code></pre>
  <p>But The return is error message</p>
  <pre><code>'{&quot;detail&quot;:[{&quot;loc&quot;:[&quot;body&quot;,&quot;files&quot;,0],&quot;msg&quot;:&quot;Expected UploadFile, received: &lt;class \'str\'&gt;&quot;,&quot;type&quot;:&quot;value_error&quot;},{&quot;loc&quot;:[&quot;body&quot;,&quot;files&quot;,1],&quot;msg&quot;:&quot;Expected UploadFile, received: &lt;class \'str\'&gt;&quot;,&quot;type&quot;:&quot;value_error&quot;},{&quot;loc&quot;:[&quot;body&quot;,&quot;files&quot;,2],&quot;msg&quot;:&quot;Expected UploadFile, received: &lt;class \'str\'&gt;&quot;,&quot;type&quot;:&quot;value_error&quot;},{&quot;loc&quot;:[&quot;body&quot;,&quot;files&quot;,3],&quot;msg&quot;:&quot;Expected UploadFile, received: &lt;class \'str\'&gt;&quot;,&quot;type&quot;:&quot;value_error&quot;}]}'
  </code></pre>
  <p>Also I tried change how to make 'files' in several ways,</p>
  <pre><code>files = [{fi:open(fi,'rb')} for fi in fis]
  files = [(fi,open(fi,'rb'),'image/jpeg') for fi in fis]
  files = [('files',(fi,open(fi,'rb'),'image/jpeg')) for fi in fis]
  </code></pre>
  <p>but all try is failed and the error message is same.</p>
  <p>How should I make files correctly?</p>