Skip to content

Instantly share code, notes, and snippets.

@stefpe
Created August 6, 2018 20:23
Show Gist options
  • Save stefpe/6246d14f90b828c17781af9c58cc9280 to your computer and use it in GitHub Desktop.
Save stefpe/6246d14f90b828c17781af9c58cc9280 to your computer and use it in GitHub Desktop.
Dropbox sync example
#!/usr/bin/env bash
readonly TOKEN=YOUR_APP_TOKEN
readonly DIR=/YOUR_DIR_PATH
FILE=$1
BASENAME=$(basename $FILE)
if [ -f "$FILE" ]; then
# upload file to dropbox
CMD="upload $DIR/$BASENAME"
HTTP_CODE=$(curl -X POST -sL -w "%{http_code}" --output /dev/null https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer $TOKEN" \
--header "Dropbox-API-Arg: {\"path\": \"$DIR/$BASENAME\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @$FILE)
else
# delete file from dropbox
CMD="delete $DIR/$BASENAME"
HTTP_CODE=$(curl -X POST -sL -w "%{http_code}" --output /dev/null https://api.dropboxapi.com/2/files/delete_v2 \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" \
--data "{\"path\": \"$DIR/$BASENAME\"}")
fi
echo $CMD
echo "Response code => $HTTP_CODE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment