Created
April 28, 2016 13:10
-
-
Save shvechikov/651098fee5ba7f0dbb92c3d8ee5d3f17 to your computer and use it in GitHub Desktop.
Upload files to S3 using generated signed URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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