簡體   English   中英

如何使用 python flask 中的圖像文件發送應用程序/json 數據?

[英]How to send application/json data with image file in python flask?

我正在使用 send_from_directory function。

@app.route('/get_data',methods=["GET"])
def get_data():
    path = os.path.join(app.config['UPLOAD_FOLDER'], 'uploads')
    return send_from_directory(path,"cat.jpg")

HTTP 響應應以一種類型的數據進行響應。 這取決於你的客戶是做什么的。

例如,您可以將 json 返回給客戶端,其中包含圖像的 URL,然后客戶端應該獲取該圖像。

Another option is to return an image and return the json data in an HTTP header, or as the first option - have an http header that contains a URL for the JSON data, and make the client fetch the JSON data later.

祝你好運:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM