-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostWithCurlUsingS3PresignedPostDict.sh
More file actions
executable file
·34 lines (28 loc) · 1.24 KB
/
Copy pathpostWithCurlUsingS3PresignedPostDict.sh
File metadata and controls
executable file
·34 lines (28 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# using e.g. boto3 to generate a presigned POST url for uploading to S3:
# https://boto3.amazonaws.com/v1/documentation/api/1.35.6/reference/services/s3/client/generate_presigned_post.html
# yields a dict with a url and a bunch of fields.
#
# We can take that data and turn it into a curl request for testing
# https://repost.aws/questions/QU2Yq1fA_mRB-yAqC2_XpkVw/s3-signed-urls-via-the-cli-for-put-using-curl
#
# But, that's a pain to format. This script lets you specify a JSON file containing that dict and generates the command for you
#
# (to use that data in Python do like:
#
# # files = { 'file': open(OBJECT_NAME_TO_UPLOAD, 'rb')}
# files = {'file': ('sample.txt', 'this is a file\ngenerated by pytest')}
# r = requests.post(upload_url, data=upload_fields, files=files)
# assert r.status_code == 204
if [ -z $2 ]; then
echo "Usage: postWithCurlUsingS3PresignedPostDict.sh <json file containing presigned info> <file to upload>"
exit 0
fi
curl --verbose -X POST \
-F key=`jq '.fields.key' $1` \
-F AWSAccessKeyId=`jq '.fields.AWSAccessKeyId' $1` \
-F x-amz-security-token=`jq '.fields["x-amz-security-token"]' $1` \
-F policy=`jq '.fields.policy' $1` \
-F signature=`jq '.fields.signature' $1` \
-F file=@$2 \
`jq -r '.url' $1`