From b358f25a6ca6a522db5fcd7bbc075fed93a984e1 Mon Sep 17 00:00:00 2001 From: Ching L Date: Sun, 29 Sep 2024 18:20:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为应用添加了图片上传功能,可以通过URL下载图片并进行压缩处理。 --- app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app.py b/app.py index cfc2dc8..945a709 100644 --- a/app.py +++ b/app.py @@ -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