title: How do I receive image and json data in FastAPI?
body: <p>I am sending and image and also json data to my API in the following way:</p>
  <pre><code>import requests
  filename = &quot;test_image.jpeg&quot;
  files = {'my_file': (filename, open(filename, 'rb'))}
  json={'first': &quot;Hello&quot;, 'second': &quot;World&quot;}
  
  response = requests.post('http://127.0.0.1:8000/file', files=files, params=json)
  </code></pre>
  <p>How do I receive both the image and json data on the server-side via FastAPI?</p>
  <p>My code looks like this:</p>
  <pre><code>@app.post('/file')
  def _file_upload(my_file: UploadFile = File(...), params: str = Form(...)):
  
      image_bytes = my_file.file.read()
      decoded = cv2.imdecode(np.frombuffer(image_bytes, np.uint8), -1)
      pg_image = cv2.resize(decoded, (220, 220))
      return {&quot;file_size&quot;: params}
  </code></pre>
  <p>However, this gives me the following error:</p>
  <pre><code>&lt;Response [422]&gt;
  {'detail': [{'loc': ['body', 'params'], 'msg': 'field required', 'type': 'value_error.missing'}]}
  </code></pre>
  <p>Is there something which I am doing wrong here?</p>