Forum Discussion

fann_96's avatar
fann_96
Explorer | Level 3
8 years ago

Get Shared Link of uploaded file programatically

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?

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,949 PostsLatest Activity: 22 hours ago
352 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!