Created
November 4, 2015 22:36
-
-
Save shentonfreude/7825c19df3934acaab99 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
# Get file path from sys.argv and upload as a presigned URL | |
import os | |
import sys | |
import boto3 | |
import requests | |
asset_path = sys.argv[1] | |
_, asset_fname = os.path.split(asset_path) | |
bucket_name = 'BUCKET_NAME' | |
ctype = 'image/jpg' | |
url_lifetime = '3600' | |
s3_client = boto3.client('s3') | |
upload_url = s3_client.generate_presigned_url( | |
'put_object', | |
Params={ | |
'Bucket': bucket_name, | |
'Key': asset_path, | |
'ContentType': ctype, | |
}, | |
ExpiresIn=url_lifetime, | |
) | |
headers = {"Content-Type": ctype} | |
data = open(asset_path, 'br') | |
print('{} {}'.format(os.path.getsize(asset_path), asset_path)) | |
try: | |
resp = requests.put(upload_url, headers=headers, data=data) | |
except Exception as e: | |
print("EXCEPTION: {}".format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this to test the limits of presigned S3 URL uploads: it's 5.0GiB, which I only found much later in AWS docs about limits of PUT.