feat(api): 添加图片上传功能
All checks were successful
continuous-integration/drone/push Build is passing

为应用添加了图片上传功能,可以通过URL下载图片并进行压缩处理。
This commit is contained in:
Ching L 2024-09-29 18:20:29 +08:00
parent f880fa6081
commit b358f25a6c

11
app.py
View File

@ -299,6 +299,17 @@ def consume():
return jsonify(response_data), 400
def upload_image(url):
# download image
img = requests.get(url)
# compress image
compress_url = 'https://upload-tinypng.tunpok.com/upload/'
resp = requests.post(compress_url, files={'file': img.content})
if resp.status_code == 200:
return resp.json()['cdn_url']
return None
@app.route("/add_recipe", methods=["POST"])
def add_recipe():
data = request.json