Upload flask FileStorage to S3
Flask usesFileStorage
as uploaded file object, it’s full package name is werkzeug.datastructures.FileStorage
.
Following is the code to upload it to s3.
def upload_file(file_storage: FileStorage):
if not file_storage.filename:
raise ApiParamError("File can't be empty.")
remote_path = secure_filename(file.filename)
file_storage.seek(0) # this is very important!!!!
bucket.put_object(Body=file_storage, Key=remote_path, ContentType=file_storage.content_type)
return remote_path
上一篇: 本地运行 Llama 2 的完整指南
下一篇: Linux 中打开 cron 日志步骤