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