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)
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)