We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.

Forum Discussion

Babaraba Abdabi's avatar
Babaraba Abdabi
Explorer | Level 4
2 years ago

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?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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's avatar
      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}"
      ```

      • Здравко's avatar
        Здравко
        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'.