Created
July 6, 2023 02:30
-
-
Save trohit/75b132938cccd4324f674cb304ddf087 to your computer and use it in GitHub Desktop.
FastAPI + serve inline image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# https://stackoverflow.com/questions/21531061/image-url-downloads-the-image-instead-of-displaying-it | |
from fastapi import FastAPI | |
from starlette.responses import FileResponse | |
app = FastAPI() | |
@app.get("/image") | |
async def get_image(): | |
#filename = "boat.jpg" # Replace with the path to your image file | |
filename = "qr.png" # Replace with the path to your image file | |
return FileResponse(filename, media_type="image/jpeg") | |
if __name__ == "__main__": | |
import uvicorn | |
uvicorn.run(app, host="0.0.0.0", port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment