Skip to content

Instantly share code, notes, and snippets.

@wpsmith wpsmith/s3Upload.sh
Created Jun 18, 2019

Embed
What would you like to do?
SH: Uploads file to IBM Cloud Object Storage (US Standard)
#!/usr/bin/env bash
# Set AWS credentials and S3 paramters
S3_KEY="YOUR_KEY_GOES_HERE"
S3_SECRET="YOUR_SECRET_GOES_HERE"
S3_BUCKET="YOUR_BUCKET_NAME_GOES_HERE"
S3_BUCKET_PATH="/"
S3_ACL="x-amz-acl:public-read"
S3_URL="https://s3.us.cloud-object-storage.appdomain.cloud/"
function s3Upload
{
# function variables.
path=$1
file=$2
aws_path=$3
aws_path="${aws_path:-$S3_BUCKET_PATH}"
# global variables.
bucket=${S3_BUCKET}
acl=${S3_ACL}
# general variables.
date=$(date +"%a, %d %b %Y %T %z")
content_type='application/json'
string="PUT\n\n$content_type\n$date\n$acl\n/$bucket$aws_path$file"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3_SECRET}" -binary | base64)
curl -X PUT -T "$path/$file" \
-H "Host: $bucket.s3.amazonaws.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$acl" \
-H "Authorization: AWS ${S3_KEY}:$signature" \
"$S3_URL$bucket$aws_path$file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.