Skip to content

Instantly share code, notes, and snippets.

@NoraCodes
Created July 2, 2018 16:53
Show Gist options
  • Select an option

  • Save NoraCodes/7323a5ade474e85460e84bf8ab76573d to your computer and use it in GitHub Desktop.

Select an option

Save NoraCodes/7323a5ade474e85460e84bf8ab76573d to your computer and use it in GitHub Desktop.
Script to upload things to Google Cloud Storage via OAuth bearer token
!/bin/bash
set -e
usage () {
echo "Usage:"
echo " upload.sh [object] [bucket] [OAuth bearer token]"
}
[ -z "$1" ] && echo "ERROR: No local object name supplied." && usage && exit 1
[ -z "$2" ] && echo "ERROR: No bucket name supplied." && usage && exit 1
[ -z "$3" ] && echo "ERROR: No bearer auth token supplied." && usage && exit 1
[ ! -f "$1" ] && echo "ERROR: Refusing to upload nonexistant file '$1'." && exit 2
curl -X POST --data-binary @"$1" \
-H "Authorization: Bearer $3" \
-H "Content-Type: application/gzip" \
"https://www.googleapis.com/upload/storage/v1/b/$2/o?uploadType=media&name=$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment