cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

Get the URL path from a link bookmark .url file

Get the URL path from a link bookmark .url file

astanley86
New member | Level 2
Go to solution

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

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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.

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

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
New member | Level 2
Go to solution

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'. 

Greg-DB
Dropbox Staff
Go to solution
[Cross-linking for reference: https://stackoverflow.com/questions/41273258/read-downloaded-blob-from-dropbox-api-using-http ]

Thanks for sharing your solution!
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    astanley86 New member | Level 2
What do Dropbox user levels mean?