Skip to content

Instantly share code, notes, and snippets.

@hassaananjum
Created March 7, 2018 06:56
Show Gist options
  • Save hassaananjum/d2b3d1978c944ec59fd7b6ac108c33f0 to your computer and use it in GitHub Desktop.
Save hassaananjum/d2b3d1978c944ec59fd7b6ac108c33f0 to your computer and use it in GitHub Desktop.
#simple script to upload image to s3 with a generic name
import boto3
import uuid
def uploadImage( img_name ):
file_name = str(uuid.uuid4())+'.png'
url = 'https://<bucket-name>.s3.amazonaws.com/'+file_name
s3 = boto3.client(
's3',
aws_access_key_id="XXXXXXXXXXXXXXXXXXXX",
aws_secret_access_key="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
endpoint_url='https://s3.amazonaws.com'
)
with open(img_name, 'rb') as data:
s3.put_object(ACL='public-read', Body=data, Bucket='<bucket-name>', ContentType='image/png', Key=file_name)
print(url)
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment