When I think about "image link", I only know about a link generated after uploading an image to a hosting service. But thank @vietnhh, now I have found another solution: make an image link from the server's hard drive via FAST API.
...
@router.get("/get-image", tags=["get image from disk"])
async def get_image_from_disk(image_path: str):
image_name = os.path.basename(image_path)
_, ext = os.path.splitext(image_name)
if os.path.exists(image_path):
return FileResponse(image_path, media_type=f"image/{ext}", filename=image_name)
return {"error": "File not found!"}
And the image's link will be something link: http://your_ip:your_port/get-image/mnt/data/images/vietnhh.jpg
Any disadvantages?
Top comments (0)