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 :: remove outliers in dataframe 
Python :: python input integer 
Python :: python 1 to 01 
Python :: display pythonpath linux 
Python :: remove a character from a string python 
Python :: how to create a python venv 
Python :: matplotlib bar chart value_counts 
Python :: python type hint for a string 
Python :: pandas apply with multiple arguments 
Python :: no migrations to apply django 
Python :: key press python 
Python :: program to tell if a number is a perfect square 
Python :: how to run for loop in python 
Python :: python create virtualenv 
Python :: one hot encoding numpy 
Python :: flask mail 
Python :: python code to remove vowels from a string 
Python :: how to playsound in python 
Python :: python palindrome string 
Python :: pandas delete first row 
Python :: how to update the kali linux os from python2 to python3 
Python :: check if is the last element in list python 
Python :: python gzip file 
Python :: python empty text file 
Python :: plot rows of dataframe pandas 
Python :: extract column numpy array python 
Python :: how to make images in python 
Python :: numpy generate random 2d array 
Python :: django connection cursor 
Python :: tkinter keep window in front 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =