从浏览器上传文件时。在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')
答案 0 :(得分:0)
更改此内容将其修复:
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)