Created
January 16, 2015 20:28
-
-
Save kenaniah/40f1ca531d57091c45ce to your computer and use it in GitHub Desktop.
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
# Povides a function that allows files to be uploaded to an Amazon S3 bucket | |
function upload_to_s3 { | |
# Definitions | |
bucket=<bucket name> | |
resource=$2/`basename $1` | |
content_type="application/x-compressed" | |
date=`date -R` | |
md5=`openssl dgst -md5 -binary "$1" | openssl enc -e -base64` | |
s3_key=<key> | |
s3_secret=<secret> | |
sigstring="PUT\n${md5}\n${content_type}\n${date}\nx-amz-server-side-encryption:AES256\n/${bucket}/${resource}" | |
signature=`echo -en ${sigstring} | openssl sha1 -hmac ${s3_secret} -binary | base64` | |
echo "Uploading $1 to $2..." | |
curl -X PUT -T "$1" \ | |
-H "Host: ${bucket}.s3.amazonaws.com" \ | |
-H "Date: ${date}" \ | |
-H "Content-Type: $content_type" \ | |
-H "Content-MD5: $md5" \ | |
-H "Authorization: AWS ${s3_key}:${signature}" \ | |
-H "x-amz-server-side-encryption: AES256" \ | |
https://${bucket}.s3.amazonaws.com/$resource | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment