从flask上传到amazon s3的文件显示大小为0B,无法打开该文件

从flask上传到amazon s3的文件显示大小为0B,无法打开该文件,flask,amazon-s3,boto3,Flask,Amazon S3,Boto3,我正在尝试使用boto将一个pdf文件从flask后端上传到AmazonS3。文件正在上载,但如果我试图在浏览器/下载中打开它,则会出现错误。显示的大小为0B。有人能告诉我原因和更正吗 表单标签 上传文件功能 def upload_file_to_s3(file, filename, acl="public-read"): try: s3.upload_fileobj( file, os.enviro

我正在尝试使用boto将一个pdf文件从flask后端上传到AmazonS3。文件正在上载,但如果我试图在浏览器/下载中打开它,则会出现错误。显示的大小为0B。有人能告诉我原因和更正吗


表单标签
上传文件功能
def upload_file_to_s3(file, filename, acl="public-read"):
    try:
        s3.upload_fileobj(
            file,
            os.environ.get('S3_BUCKET'),
            filename,
            ExtraArgs={
                "ACL": acl,
                "ContentType": file.content_type
            }
        )
    except Exception as e:
        # This is a catch all exception, edit this part to fit your needs.
        print("Something Happened: ", e)
        return e
    temp = os.environ.get('S3_LOCATION').format(os.environ.get("S3_BUCKET"))
    return "{}{}".format(temp, filename)
谢谢您的时间:)

@app.route("/profile", methods=['GET', 'POST'])
@login_required
def profile():
    form=ProfileForm()
    if form.validate_on_submit():
        myfile = request.files["document"]
        print(myfile.filename)
        print(upload_file_to_s3(myfile, myfile.filename))
    return render_template("profile_form.html", title='Home', form=form)
def upload_file_to_s3(file, filename, acl="public-read"):
    try:
        s3.upload_fileobj(
            file,
            os.environ.get('S3_BUCKET'),
            filename,
            ExtraArgs={
                "ACL": acl,
                "ContentType": file.content_type
            }
        )
    except Exception as e:
        # This is a catch all exception, edit this part to fit your needs.
        print("Something Happened: ", e)
        return e
    temp = os.environ.get('S3_LOCATION').format(os.environ.get("S3_BUCKET"))
    return "{}{}".format(temp, filename)