Search code examples
javascriptnode.jsurldropboxdropbox-api

NODEJS ,DROPBOX redirection LINK


I want to know if its possible to open using nodeJS a link(number 1) that lead to second(link number 2) then retrieve the url of the second one. the purpose behind this is that i want to use this operation to retrieve a direct link from the shared link of DROPBOX.the shared redirect me to another link which a need to operate some modification on it to get the direct link.


Solution

  • If you're trying to get a direct link from a shared link, you can just change the domain name from www.dropbox.com to dl.dropboxusercontent.com. See https://www.dropbox.com/developers/blog/53/programmatically-download-content-from-share-links.

    EDIT:

    And if you really do need to follow a redirect first, try something like this:

    var http = require('http');
    
    var url = '...';
    http.get(url, function (res) {
        if (res.statusCode === 301 || res.statusCode === 302) {
            console.log('Redirected to: ' + res.headers.location);
        }
    });