cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in learning how media industry leaders use Dropbox Replay? Register for our webinar 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: 

I want to obtain the URL of a file on Dropbox via an API.

I want to obtain the URL of a file on Dropbox via an API.

Babaraba Abdabi
Explorer | Level 4

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 5

Greg-DB
Dropbox Staff

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 Abdabi
Explorer | 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}"
```

Здравко
Legendary | 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-DB
Dropbox Staff

@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 Abdabi
Explorer | 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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Babaraba Abdabi Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?