title: Why do I get an "Unprocessable Entity" error while uploading an image with FastAPI?
body: <p>I am trying to upload an image but FastAPI is coming back with an error I can't figure out.</p>
  <p>If I leave out the &quot;<code>file: UploadFile = File(...)</code>&quot; from the function definition, it works correctly. But when I add the <code>file</code> to the function definition, then it throws the error.</p>
  <p>Here is the complete code.</p>
  <pre><code>@router.post('/', response_model=schemas.PostItem, status_code=status.HTTP_201_CREATED)
  def create(request: schemas.Item, file: UploadFile = File(...), db: Session = Depends(get_db)):
  
      new_item = models.Item(
          name=request.name,
          price=request.price,
          user_id=1,
      )
      print(file.filename)
      db.add(new_item)
      db.commit()
      db.refresh(new_item)
      return new_item
  </code></pre>
  <p>The <code>Item</code> Pydantic model is just</p>
  <pre><code>class Item(BaseModel):
      name: str
      price: float
  </code></pre>
  <p>The error is:<br />
  Code 422    Error: Unprocessable Entity</p>
  <pre><code>{
    &quot;detail&quot;: [
      {
        &quot;loc&quot;: [
          &quot;body&quot;,
          &quot;request&quot;,
          &quot;name&quot;
        ],
        &quot;msg&quot;: &quot;field required&quot;,
        &quot;type&quot;: &quot;value_error.missing&quot;
      },
      {
        &quot;loc&quot;: [
          &quot;body&quot;,
          &quot;request&quot;,
          &quot;price&quot;
        ],
        &quot;msg&quot;: &quot;field required&quot;,
        &quot;type&quot;: &quot;value_error.missing&quot;
      }
    ]
  }
  </code></pre>