我正在尝试将照片文件上传到我的s3存储桶。有时可以成功上传,但是在大多数情况下,我收到以下错误:
botocore.exceptions.ClientError: An error occurred (BadDigest) when calling the PutObject operation (reached max retries: 4): The Content-MD5 you specified did not match what we received.
我是Flask的新手,正在使用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'])
s3 = boto3.resource('s3')
s3.Bucket('thtack').put_object(Key=filename, Body=request.files['photo'])
row = User.query.filter_by(user_id = user_id).first()
row.img_url = filename
updated_filename = row.img_url
db.session.commit()
它有时可以工作,但大多数时候不行,并抛出此错误。我要上传到S3的图像是用户作为个人资料图片导入的图像。预先感谢