Skip to content

Instantly share code, notes, and snippets.

@shvechikov
Created April 28, 2016 13:10
Embed
What would you like to do?
Upload files to S3 using generated signed URLs
import requests
from boto.s3.connection import S3Connection
c = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KET)
data = 'file content'
filename = 'dir/name.txt'
bucket_name = 'your-bucket-name'
headers = {'Content-Type': 'text/plain'}
# Generate signed url
url = c.generate_url(
expires_in=300,
method='PUT',
bucket=bucket_name,
key=filename,
headers=headers,
#force_http=True,
)
# Upload file
requests.put(url, data=data, headers=headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment