Fastapi: Possible/How to set content type for UploadFile?

Created on 10 Aug 2020  路  1Comment  路  Source: tiangolo/fastapi

First check

  • [x] I added a very descriptive title to this issue.
  • [x] I used the GitHub search to find a similar issue and didn't find it.
  • [x] I searched the FastAPI documentation, with the integrated search.
  • [x] I already searched in Google "How to X in FastAPI" and didn't find any information.
  • [x] I already read and followed all the tutorial in the docs and didn't find an answer.
  • [x] I already checked if it is not related to FastAPI but to Pydantic.
  • [x] I already checked if it is not related to FastAPI but to Swagger UI.

Example

Here's a self-contained, minimal, reproducible, example with my use case:

from fastapi import FastAPI, File, UploadFile

app = FastAPI()


@app.get("/")
def file_upload(file: UploadFile = File(..., media_type='text/xml')):
    return {"Hello": "World"}

Description

The schema created for this file doesn't mention the specified media type. (see: OpenAPI 'Specifying Content-Type')
How is a application supposed to know what kind of files it can send?

I'd expect something like

encoding: {
        "file": {"contentType": "text/xml"}
}

Environment

  • OS: Windwos 10
  • FastAPI Version: 0.60.1
  • Python version: 3.8
question

Most helpful comment

See similar #1018. Looks interesting, down to work on a fix for this!

>All comments

See similar #1018. Looks interesting, down to work on a fix for this!

Was this page helpful?
0 / 5 - 0 ratings