How do I return an image in fastAPI?

前端 未结 6 1909
灰色年华
灰色年华 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:37

    All the other answer(s) is on point, but now it's so easy to return an image

    from fastapi.responses import FileResponse
    
    @app.get("/")
    async def main():
        return FileResponse("your_image.jpeg")
    

提交回复
热议问题