Created
July 2, 2018 16:53
-
-
Save NoraCodes/7323a5ade474e85460e84bf8ab76573d to your computer and use it in GitHub Desktop.
Script to upload things to Google Cloud Storage via OAuth bearer token
This file contains hidden or 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
| !/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