Skip to content

Instantly share code, notes, and snippets.

@windhooked
Forked from harshavardhana/curl-s3-v2.sh
Created August 26, 2019 16:31
Show Gist options
  • Save windhooked/5268f8436c7a42758a38ea8bc3d5b61d to your computer and use it in GitHub Desktop.
Save windhooked/5268f8436c7a42758a38ea8bc3d5b61d to your computer and use it in GitHub Desktop.
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="YOUR-ACCESSKEY"
S3SECRET="YOUR-SECRETKEY"
function putS3
{
path=$1
file=$2
aws_path=$3
bucket='my-bucket'
date=$(date +"%a, %d %b %Y %T %z")
content_type='application/octet-stream'
string="PUT\n\n$content_type\n$date\n\n/$bucket$aws_path$file"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
curl -X PUT -T "$path/$file" \
-H "Host: play.minio.io:9000" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://play.minio.io:9000/$bucket/$aws_path$file"
}
for file in "$path"/*; do
putS3 "$path" "${file##*/}" "/path/on/s3/to/files/"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment