cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know more about how Community ideas impact Dropbox development? Check it out here

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Give file public access after upload through shell script

Give file public access after upload through shell script

tobiasger
Helpful | Level 5

I've used the following code for uploading a file through a shell script in Automator on macOS:

 

DROPBOX_TOKEN="MY-TOKEN"
FILE=$1
FILENAME=$(basename "$FILE")

UPLOAD=`curl -sX POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer $DROPBOX_TOKEN" \
--header "Dropbox-API-Arg: {\"path\": \"/psds/$FILENAME\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @"$FILE"`

 

 That works like a charm. I am then using IFTTT with an applet that looks for new files in this folder and then creates a Tumblr post with the file, using it's previewUrl as the caption. This preview URL is by default only allowing me as the owner to see the file. I'm looking into if there is a way to give the file public access when uploading it.

So I tried adding this to the shell script:

 

UPLOAD=`curl -sX POST https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings \
--header "Authorization: Bearer $DROPBOX_TOKEN" \
--header "Dropbox-API-Arg: {\"path\": \"/psds/$FILENAME\",\"settings\": {\"audience\": \"public\",\"access\": \"viewer\",\"requested_visibility\": \"public\",\"allow_download\": true}}" \
--header "Content-Type: application/octet-stream" \

 

But that is not working. When looking on the file in Dropbox after the upload, it still says that only I got access to it.

 

Is there a way to give a file public access when uploading it through the API like this?

1 Accepted Solution

Accepted Solutions

Re: Give file public access after upload through shell script

tobiasger
Helpful | Level 5

Turns out that I was a bit ignorant when looking at what to put in the request. The right request should look like this:

UPLOAD=`curl -sX POST https://api.dropbox.com/2/sharing/create_shared_link_with_settings \
--header "Authorization: Bearer $DROPBOX_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"path\": \"/psds/$FILENAME\",\"settings\": {\"audience\": \"public\",\"access\": \"viewer\",\"requested_visibility\": \"public\",\"allow_download\": true}}"`

View solution in original post

2 Replies 2

Re: Give file public access after upload through shell script

Greg-DB
Dropboxer

The /2/sharing/create_shared_link_with_settings endpoint is the right way to create a shared link for a file, e.g., for public access. Can you print out the response body you get from that call? It should contain either the result, with the created shared link, or an error indicating why the call failed.

Re: Give file public access after upload through shell script

tobiasger
Helpful | Level 5

Turns out that I was a bit ignorant when looking at what to put in the request. The right request should look like this:

UPLOAD=`curl -sX POST https://api.dropbox.com/2/sharing/create_shared_link_with_settings \
--header "Authorization: Bearer $DROPBOX_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"path\": \"/psds/$FILENAME\",\"settings\": {\"audience\": \"public\",\"access\": \"viewer\",\"requested_visibility\": \"public\",\"allow_download\": true}}"`

View solution in original post

Who's talking

Top contributors to this post

  • User avatar
    tobiasger Helpful | Level 5
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?