Skip to content

Instantly share code, notes, and snippets.

@nmolivo
Created September 23, 2018 23:48
Show Gist options
  • Save nmolivo/68af26a2dea66aa9b02c4ec739b9075f to your computer and use it in GitHub Desktop.
Save nmolivo/68af26a2dea66aa9b02c4ec739b9075f to your computer and use it in GitHub Desktop.
# programmatically edit metadata of s3 bucket files, so the links open in a browser tab and do not download
# to your computer when clicked
client = boto3.client('s3', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
for i in html_list:
key = i
k = client.head_object(Bucket = bucket_name, Key = key)
client.copy_object(Bucket = bucket_name, Key = key, CopySource = bucket + '/' + key, ContentType ='text/html', MetadataDirective='REPLACE')
client = boto3.client('s3', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
for i in pdf_list:
key = i
k = client.head_object(Bucket = bucket_name, Key = key)
client.copy_object(Bucket = bucket_name, Key = key, CopySource = bucket + '/' + key, ContentType ='application/pdf', ContentDisposition = 'inline', MetadataDirective='REPLACE')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment