Permalink
Switch branches/tags
Nothing to show
Find file Copy path
b0041ff Feb 4, 2016
19 lines (14 sloc) 685 Bytes
#!/bin/bash
# Upload a file to Google Drive
#
# Usage: upload.sh <access_token> <file> [title] [path] [mime]
set -e
ACCESS_TOKEN=$1
BOUNDARY=`cat /dev/urandom | head -c 16 | xxd -ps`
MIME_TYPE=${5:-"application/octet-stream"}
( echo -en "--$BOUNDARY\nContent-Type: application/json; charset=UTF-8\n\n{ \"title\": \"$3\", \"parents\": [ { \"id\": \"$4\" } ] }\n\n--$BOUNDARY\nContent-Type: $MIME_TYPE\n\n" \
&& cat $2 && echo -en "\n\n--$BOUNDARY--\n" ) \
| curl -v "https://www.googleapis.com/upload/drive/v2/files/?uploadType=multipart" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: multipart/related; boundary=\"$BOUNDARY\"" \
--data-binary "@-"