-
Copy the
generate.py
script to your machine. -
Update the
BUCKET_NAME
andKEY_NAME
values in the script as needed. -
Run
python generate.py
. It will spit some output like the following:$ python3 generate.py curl command: curl -v -F key=cat.jpg \ -F AWSAccessKeyId=AKIANOTAKEY \ -F policy=eyKJLJSDFLKJASDLFJLAKSDJFLJASDLFAKLNFLNASDJFLAJSDLKFJ== \ -F signature=4jsdlkjasdljfljsdljf/5A= \ -F [email protected] \ https://presigned-post-example.s3.amazonaws.com/
-
Copy and paste the
curl
command into your terminal to upload the file.
Created
February 1, 2019 01:59
-
-
Save alexdebrie/3e8b96217f5aff01227050b17a24e380 to your computer and use it in GitHub Desktop.
Using boto3 generate_presigned_post()
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 boto3 | |
# Change BUCKET_NAME to your bucket name and | |
# KEY_NAME to the name of a file in the directory where you'll run the curl command. | |
BUCKET_NAME = 'presigned-post-example' | |
KEY_NAME = 'cat.jpg' | |
s3 = boto3.client('s3') | |
resp = s3.generate_presigned_post( | |
Bucket=BUCKET_NAME, | |
Key=KEY_NAME, | |
) | |
resp['fields']['file'] = '@{key}'.format(key=KEY_NAME) | |
form_values = "\n ".join(["-F {key}={value} \\".format(key=key, value=value) | |
for key, value in resp['fields'].items()]) | |
print('curl command: \n') | |
print('curl -v {form_values} \n {url}'.format(form_values=form_values, url=resp['url'])) | |
print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we use wildcard for the key name like (/path/*)