How do I return an image in fastAPI?

前端 未结 6 1911
灰色年华
灰色年华 2020-12-14 17:51

Using the python module fastAPI, I can\'t figure out how to return an image. In flask I would do something like this:

@app.route(\"/vector_image\", methods=[         


        
6条回答
  •  情歌与酒
    2020-12-14 18:57

    It's not properly documented yet, but you can use anything from Starlette.

    So, you can use a FileResponse if it's a file in disk with a path: https://www.starlette.io/responses/#fileresponse

    If it's a file-like object created in your path operation, in the next stable release of Starlette (used internally by FastAPI) you will also be able to return it in a StreamingResponse.

提交回复
热议问题