title: Uploading images in FastAPI post request causes 400 Bad Request
body: <p>I would like to get image via post request and then read it. I'm trying to do is this way:</p>
  
  <pre><code>import numpy as np
  from PIL import Image
  from fastapi import FastAPI, File, UploadFile, HTTPException, Depends
  app = FastAPI()
  @app.post("/predict_image")
      @logger.catch
      def predict_image(predict_image: UploadFile = File(...)):
          logger.info('predict_image POST request performed')
          try:
              pil_image = np.array(Image.open(predict_image.file))
          except:
              raise HTTPException(
                  status_code=HTTP_422_UNPROCESSABLE_ENTITY, detail="Unable to process file"
              )
          pred = pil_image.shape
          logger.info('predict_image POST request performed, shape {}'.format(pred))
      return {'input_shape': pred}
  </code></pre>
  
  <p>Calling post request returns <code>INFO:     127.0.0.1:59364 - "POST /predict_image HTTP/1.1" 400 Bad Request</code></p>
  
  <p><a href="https://i.stack.imgur.com/aTkTF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aTkTF.png" alt="enter image description here"></a></p>
  
  <p>How to fix it?</p>
  
  <p>UPD:</p>
  
  <p>Example from official tutorial return same exception:</p>
  
  <pre><code>@app.post("/uploadfile/")
  async def create_upload_file(file: UploadFile = File(...)):
      return {"filename": file.filename}
  </code></pre>