You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

astanley86's avatar
astanley86
New member | Level 2
9 years ago

Get the URL path from a link bookmark .url file

Hello,

 

In my dropbox folder I have a bookmark to a website URL.  For example: http://www.google.com - this will be saved as 'Google.url' in my dropbox folder.

 

Which API will return 'http://www.google.com' so that in my app I can make this a clickable link?  

 

Thank you,

 

Andrew

  • For .url files, the URL information is saved in the file content. You can use /2/files/download to download the file content, and then parse and use it as desired. 

     

    Using your example, if the file is saved as "Google.url" in your Dropbox root folder, you would supply the path "/Google.url" to download the file using the endpoint linked above (or the corresponding method if you're using an SDK or library) and then parse the URL from the returned file content in the response body.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    For .url files, the URL information is saved in the file content. You can use /2/files/download to download the file content, and then parse and use it as desired. 

     

    Using your example, if the file is saved as "Google.url" in your Dropbox root folder, you would supply the path "/Google.url" to download the file using the endpoint linked above (or the corresponding method if you're using an SDK or library) and then parse the URL from the returned file content in the response body.

    • astanley86's avatar
      astanley86
      New member | Level 2

      Thank you, Greg.  This gave me what I needed!  

       

      I was not familiar with what to with the raw binary data returned from Dropbox.  After combining some answers from StackOverflow this is what I came up with which is working for me in my Angular 1 application.  I hope this code will help someone else who might be looking for this!

       

                  function downloadFile(filePath) {
                      if (!filePath) {
                          console.error('Cannot download file because no file was specified.');
                          return;
                      }
                      return $q(function(fulfill, reject) {
                          $http({
                              url: `${dropboxContent}/2/files/download`,
                              method: 'POST',
                              headers: {
                                  'Authorization': 'Bearer {{access-token-goes-here}}',
                                  'Dropbox-API-Arg': `{"path": "${filePath}"}`
                              },
                              responseType: 'blob'
                          }).then(
                              results => {
                                  // data received from dropbox is binary data saved as a blob
                                  // The FileReader object lets web applications asynchronously read the contents of files
                                  // https://developer.mozilla.org/en-US/docs/Web/API/FileReader
                                  var fileReader = new FileReader();
                                   // function will run after successfully reading the file
                                  fileReader.onload = function() {
                                      var string = this.result; // store the file contents
                                      string = encodeURI(string); // get rid of the paragraph return characters
                                      var endPosition = string.indexOf('%0D%0A', 32); // find the end of the URL, startPosition is 32
                                      var actualURL = string.substring(32, endPosition); // grab only the characters between start and end positions
                                      fulfill(actualURL);
                                  };
                                  fileReader.readAsText(results.data);                           
                              },
                              error => reject(error));
                      });
                  }

      The tricky part is that you have to be able to 'read' the blob that is returned, and then extract out just the 'URL'. 

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 3 days ago
333 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!