如何在fastAPI中返回图像?

如何在fastAPI中返回图像?,第1张

如何在fastAPI中返回图像

我有一个类似的问题,但带有cv2图像。这可能对其他人有用。使用

StreamingResponse

import iofrom starlette.responses import StreamingResponseapp = FastAPI()@app.post("/vector_image")def image_endpoint(*, vector):    # Returns a cv2 image array from the document vector    cv2img = my_function(vector)    res, im_png = cv2.imenpre(".png", cv2img)    return StreamingResponse(io.BytesIO(im_png.tobytes()), media_type="image/png")


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5655315.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存