Flask Upload Image Directly To S3 Without Saving In Server

Flask Upload Image Directly To S3 Without Saving In Server

Easily Upload to S3 Bucket using Flask

Santhosh Thomas
·Jul 1, 2021·

Subscribe to my newsletter and never miss my upcoming articles

import boto3
s3 = boto3.client( "s3", aws_access_key_id= "*************", aws_secret_access_key="**********" )


@login_blueprint.route('/uploadfile', methods=['POST']) 

file= request.files['file'] 

try: 
    filename = secure_filename(file.filename) 
    acl="public-read" 
    s3.upload_fileobj( file, 'bucket-name', file.filename, ExtraArgs={ "ACL": acl, "ContentType": file.content_type } ) 

except Exception as e:
    resp = jsonify(e)
    resp.status_code =200 
    return resp
Buy Me A Coffee" data-card-controls="0" data-card-theme="light">Buy Me A Coffee
 
Share this