We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

tobiasger's avatar
tobiasger
Helpful | Level 5
4 years ago

Give file public access after upload through shell script

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?

  • 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}}"`
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    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.

    • tobiasger's avatar
      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}}"`

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API

Make connections with other developers

795 PostsLatest Activity: 6 days ago
192 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!