Skip to content

Instantly share code, notes, and snippets.

@shvechikov
Created April 28, 2016 13:10
Show Gist options
  • Save shvechikov/651098fee5ba7f0dbb92c3d8ee5d3f17 to your computer and use it in GitHub Desktop.
Save shvechikov/651098fee5ba7f0dbb92c3d8ee5d3f17 to your computer and use it in GitHub Desktop.
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