Cut the Clutter: Test Ignore Files Feature - sign up to become a beta tester here.
Forum Discussion
Babaraba Abdabi
3 years agoExplorer | Level 4
I want to obtain the URL of a file on Dropbox via an API.
I want to get the URL of the file for users with the appropriate access permissions to the file. This is not about the shared link URL.
Is there an API to get the URL of a file on Dropbox? Or is there a way to construct the URL of a file on Dropbox?
5 Replies
- Greg-DB3 years ago
Dropbox Community Moderator
The Dropbox API doesn't offer a way to get/construct the URL of a file on the Dropbox web site (like with "/home") exactly, but you can call /2/sharing/create_shared_link_with_settings with the 'path' set to the the file/folder, and 'settings.audience' to 'no_one' to get a shared link that would refer to the folder on the web site for anyone who has access to it, though not directly enable any additional access to it.
- Babaraba Abdabi3 years agoExplorer | Level 4
Thank you for your reply.
I understand that there is no API to obtain the URL for direct access (not sharing url).In that case, I am considering a way to construct a link URL from the file path. Can I assume that all can be accessed from under `/home/` ?
example)
```
lower_path = "/foo/bar/baz/something.pdf"
dirname = File.dirname(lowerpath) # /foo/bar/baz
basename = File.basename(lowerpath) # something.pdf
"https://www.dropbox.com/home#{dirname}?preview=#{basename}"
``` - Здравко3 years agoLegendary | Level 20
Babaraba Abdabi wrote:...
"https://www.dropbox.com/home#{dirname}?preview=#{basename}"
...Hi Babaraba Abdabi,
Such a link may appear valid for file, but take in mind that it's very context specific (login session specific). You should make sure the user has logged in the same context where you got your dirname/basename from. Otherwise the link could appear invalid or even worse - link may be valid but pointing something completely different (something that's difficult to trace).
You may got confused from Greg's proposal for usage of /2/sharing/create_shared_link_with_settings. In spite part of 'sharing' family of calls, while set 'no_one' as audience, this link appear absolutely equivalent to the your proposal, except it doesn't depend on the context (i.e. much more stable and not shared one in fact - despite of the 'family' - you're sharing to 'no_one'). 😉
Hope this clarifies matter.
Add: Something else you may be interested in. Instead of creating new link, you can get a link every file has already. Just call /2/sharing/get_file_metadata to a file of interest (either shared or not). In the result's filed 'preview_url' you will receive preexisting link of type 'no_one'.
- Greg-DB3 years ago
Dropbox Community Moderator
Babaraba Abdabi As Здравко mentioned, you shouldn't assume that a link constructed like that will be necessarily correct always. We don't officially support building links like that; I recommend trying out the 'no_one' shared link option that I mentioned and that Здравко reiterated, as it sounds like it would be useful for your scenario.
- Babaraba Abdabi3 years agoExplorer | Level 4
Thank you for your replies.
I see, I understand that the case where constructing a URL is effective is extremely limited, and it is generally better to use the no_one sharing link.
My question has been resolved.
Thank you for your answers. These were really helpful.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,039 PostsLatest Activity: 2 days ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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!