Skip to content

Instantly share code, notes, and snippets.

@anthonyeden
Created September 20, 2016 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonyeden/7a9c318964f4688efabdc9b014e4ff98 to your computer and use it in GitHub Desktop.
Save anthonyeden/7a9c318964f4688efabdc9b014e4ff98 to your computer and use it in GitHub Desktop.
DreamObjects Sample Upload Script (Bash)
#!/bin/bash
function uploadDreamObjects {
# Uploads a single file to the DreamObjects S3-style API
# Sample code provided by http://mediarealm.com.au/
# Based on https://gist.github.com/chrismdp/6c6b6c825b07f680e710
# Also https://raw.githubusercontent.com/fredericofs/s3.bash/master/simple_version_working
# And http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
DREAMKEY="MYKEY"
DREAMSECRET="MYSECRET"
path="$1"
file="$2"
dream_path="$3"
bucket="$4"
full_path="${bucket}${dream_path}${file}"
date=`date -R -u`
content_type='application/x-compressed-tar'
string="PUT\n\n${content_type}\n${date}\n/${full_path}"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${DREAMSECRET}" -binary | base64)
curl -X PUT -T "${path}/${file}" \
-H "Host: ${bucket}.objects-us-west-1.dream.io" \
-H "Date: ${date}" \
-H "Content-Type: ${content_type}" \
-H "Authorization: AWS ${DREAMKEY}:${signature}" \
"https://${bucket}.objects-us-west-1.dream.io${dream_path}${file}"
}
# Example Usage 1
# Uploads '/path/to/file/mybackup.tar.gz'
# Stores as '/boo/mybackup.tar.gz'
# Bucket name: 'my-sample-bucketname'
uploadDreamObjects "/path/to/file/" "mybackup.tar.gz" "/boo/" "my-sample-bucketname"
# Example Usage 2
# Uploads '/path/to/file/my-filename-to-upload.tar.gz'
# Stores as '/YYYY-MM-DD/my-filename-to-upload.tar.gz'
# Bucket name: 'my-sample-bucketname'
uploadDreamObjects "/path/to/file/" "my-filename-to-upload.tar.gz" "/$(date +%F)/" "my-sample-bucketname"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment