Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flask upload file to s3

from werkzeug import secure_filename

@user_api.route('upload-profile-photo', methods=['PUT'])
@Auth.auth_required
def upload_profile_photo():
    """
    Upload User Profile Photo
    """
    key = Auth.auth_user()
    bucket = 'profile-photos'
    content_type = request.mimetype
    image_file = request.files['file']

    client = boto3.client('s3',
                          region_name='sfo2',
                          endpoint_url='https://example.xxx.amazonaws.com',
                          aws_access_key_id=os.environ['ACCESS_KEY'],
                          aws_secret_access_key=os.environ['SECRET_KEY'])

    filename = secure_filename(image_file.filename)  # This is convenient to validate your filename, otherwise just use file.filename

    client.put_object(Body=image_file,
                      Bucket=bucket,
                      Key=filename,
                      ContentType=content_type)

    return custom_response({'message': 'image uploaded'}, 200)

Comment

flask Upload file to local s3

import boto3
session = boto3.session.Session()

s3 = session.client(
            service_name='s3',
            endpoint_url='http://localhost:4566',
        )
bucket_name = "mybucket"
s3.upload_fileobj(uploadedFile, bucket_name, file_name)
Comment

PREVIOUS NEXT
Code Example
Python :: Herons rule python 
Python :: task orchestration framework 
Python :: starter is a naive datetime. Use pytz to make it a "US/Pacific" datetime instead and assign this converted datetime to the variable local. 
Python :: ignore transformers warning 
Python :: python plot auc 95% confidence intervals stackoverflow 
Python :: pandas converters example 
Python :: python time a code segment 
Python :: operation that returns True if all values are equal 
Python :: iris data pandas scatterplot 
Python :: pandas convert text duration to minutes 
Python :: matplotlib colorbar reverse direction 
Python :: get random vowel python 
Python :: pydictionary 
Python :: text to qr code python 
Python :: mp.solutions.findhands not in python 3.8 
Python :: break outside loop python 
Python :: seaborn plot to see outliers 
Python :: spacegoat meaning 
Python :: python numpy bbox 
Python :: pandas 3d set camara cords 
Python :: print hello in python 
Python :: keep calm and carry on memes 
Python :: multiplication table for number python codewars 
Python :: serialization in python 
Python :: tkinter call function in mainloop 
Python :: np.random.choice replace 
Python :: python find last index of character in string 
Python :: the range() function 
Python :: fizz buzz fizzbuzz python game 
Python :: TypeError: expected str, bytes or os.PathLike object, not list 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =