cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

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

Get Shared Link of uploaded file programatically

Get Shared Link of uploaded file programatically

fann_96
Explorer | Level 3

I can use this code to upload my file to the dropbox through html.

 

<script>
function handleFileSelect(evt) { var files = evt.target.files; // FileList object //// files is a FileList of File objects for (var i = 0, f; f = files[i]; i++) { $.ajax({ url: 'https://content.dropboxapi.com/2/files/upload', type: 'post', data: f, processData: false, contentType: 'application/octet-stream', headers: { "Authorization": "Bearer <REDACTED>", "Dropbox-API-Arg": '{"path": "/' + f.name + '","mode": "add"}' }, success: function (data) { console.log(data); }, error: function (data) { console.log(data); } }) } } document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

However, I would like to get the shared link of the uploaded file. I tried this code but couldn't get it.

<script>
        function handleSharedLink(evt) {
            var path = "TARCpace.apk";

            $http.post("https://api.dropboxapi.com/2/sharing/get_shared_links",
                JSON.stringify({
                    "path": path
                }),
                {
                    headers: {
                        'Content-Type': "application/json",
                        'Authorization': "Bearer <REDACTED>"
                    }
                }
            ).then(function (data) {
                    console.log(data);
                    $('#output').html(result);
            })
        }

 
  var output = document.getElementById('getlink').addEventListener('click', handleSharedLink, false);
</script>

How can i get the shared link? Is the method correct?

1 Reply 1

Greg-DB
Dropbox Staff

[Cross-linking for reference: https://stackoverflow.com/questions/47237857/get-dropbox-shared-link-after-uploaded-a-file-programat... ]

 

If you want to retrieve existing shared links, you should use /2/sharing/list_shared_links. (The /2/sharing/get_shared_links endpoint also technically works, but it is deprecated.)

 

If you need to create a new one, you should use /2/sharing/create_shared_link_with_settings. (For reference, your StackOverflow post used /2/files/get_temporary_link, which is also fine if that's what you want. That will give you a temporary direct link to the file that expires after four hours.)

 

By the way, you posted your access token. I redacted it, but for the sake of security, you should disable that access token. You can do so by revoking access to the app entirely, if the access token is for your account, on the connected apps page. Or, you can disable just this access token using the /2/auth/token/revoke endpoint.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?