简体   繁体   English

在s3存储桶中创建的文件,但文件为空

[英]file created in s3 bucket but file is empty

while uploading a file from the browser. 从浏览器上传文件时。 filename is created in the s3 bucket but the content of the file is empty. filename在s3存储桶中创建,但文件内容为空。

    @app.route("/", methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            file = request.files['file']
            file.filename = time.strftime("%Y%m%d-%H%M%S") ## filename=TIMESTAMP

            # Read the contents of the file
            file_contents = file.open()
            s3.Object('mybucket', file.filename).put(file_contents)

            # Connect to s3 bucket
            s3=boto3.resource('s3')
        return render_template('index.html')

changing this fixed it: 更改此固定它:

file_contents = file.open() ---> file_contents = file.read()

s3.Object('mybucket', file.filename).put(file_contents) --> s3.Object('mybucket', file.filename).put(Body=file_contents)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM