0、前言
需求:实现python封装将本地图片存储至minio中的POST接口和获取图片下载外链的get接口,实现前端调用实现图片上传和下载
1、后端接口
# 上传图片接口
@app.route("/upload_image", methods=["POST"])
def upload_image():
data = request.json
bucket_name = data.get("bucket_name")
directory_path = data.get("directory_path")
image_path = data.get("image_path")
if not all([bucket_name, directory_path, image_path]):
return jsonify({"status": "error", "message": "缺少必要的参数"})
result = bucket.upload_image(bucket_name, directory_path, image_path)
return jsonify(result)
# 获取图片外链接口
@app.route("/get_image_url", methods=["GET"])
def get_image_url():
bucket_name = request.args.get("bucket_name")
image_path = request.args.get("image_path")
if not all([bucket_name, image_path]):
return jsonify({"status": "error", "message": "缺少必要的参数"})
result = bucket.get_image_url(bucket_name, image_path)
return jsonify(result)

最低0.47元/天 解锁文章
1034

被折叠的 条评论
为什么被折叠?



