One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
fann_96
8 years agoExplorer | Level 3
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?
- Greg-DB
Dropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/47237857/get-dropbox-shared-link-after-uploaded-a-file-programatically ]
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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,949 PostsLatest Activity: 22 hours ago
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!