python - 在将图像上传到 s3 存储桶之前压缩图像
问题描述
我想在将用户的个人资料图片上传到我的 s3 存储桶之前对其进行压缩。我有一个烧瓶应用程序。
这是我的代码:
@app.route("/profile", methods=["GET", "POST"])
@login_required
def profile():
if request.method == "POST":
user_id = session["user_id"]
if request.files['photo']:
filename = photos.save(request.files['photo'])
## here should go the code to compress the image
s3 = boto3.resource('s3')
s3.Bucket('mybucketname').upload_file("static/img/" + filename, filename)
row = User.query.filter_by(user_id = user_id).first()
row.img_url = filename
updated_filename = row.img_url
db.session.commit()
我是 python 新手。我尝试使用 PIL 实现一个,但未能调整教程中的代码。如果你们能帮助我,我将不胜感激。
解决方案
推荐阅读
- ios - OCMock 返回未调用的方法,但我确信它是
- mysql - MySQL - 选择日期时间列前 1 小时的行
- c# - .Net 引用不同版本库的麻烦
- amazon-web-services - 适用于 RDS 的 AWS cloudwatch 警报
- linker - 我如何知道 ld 使用的库的路径?
- node.js - 为什么npm单独安装时会安装相同依赖的两个不同版本
- r - Mystery Matrix Subset
- kotlin - How to hash data class with array property
- javascript - MongoError:过滤器参数必须是一个对象
- android - 我怎样才能得到三个#之后的子字符串?