Skip to content

Instantly share code, notes, and snippets.

@lantrix
Last active April 5, 2019 02:56
Show Gist options
  • Save lantrix/2edd888a57d7a4a4d825991d5efdc588 to your computer and use it in GitHub Desktop.
Save lantrix/2edd888a57d7a4a4d825991d5efdc588 to your computer and use it in GitHub Desktop.
Save a file from somewhere on the web direct to dropbox
#!/bin/bash
# Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
# Click on "Create App", then select "Dropbox API app"
# Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder
# Enter the "App Name" that you prefer
# Now, click on the "Create App" button.
# When your new App is successfully created, please click on the Generate button
# under the 'Generated access token' section, then copy and paste the new access token here:
bearer="myGeneratedTokenHere"
# Populate the File URL, save name and save folder in Dropbox:
url='https://www.hamrick.com/files/vuex6496.dmg'
f='vuex6496.dmg'
save_folder='/test/' #trailing slash and leading slash for /key/path/ - e.g. '/myfolder/SubFolder/'
# Action!
command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq but it's not installed. Aborting."; exit 1; }
command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Aborting."; exit 1; }
job=$(curl https://api.dropboxapi.com/2/files/save_url --silent \
-H "Authorization: Bearer ${bearer}" \
-H "Content-Type: application/json" \
-d "{\"path\": \"${save_folder}${f}\",\"url\": \"${url}\"}")
j=$(echo $job | jq -r '.async_job_id')
# status
complete='false'
while [[ $complete == "false" ]]; do
sleep 3
status=$(curl https://api.dropboxapi.com/2/files/save_url/check_job_status --silent \
-H "Authorization: Bearer ${bearer}" \
-H "Content-Type: application/json" \
-d "{\"async_job_id\": \"${j}\"}")
if [[ $status == *"in_progress"* ]]; then
complete='false'
else
complete='true'
fi
echo $status | jq
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment