IFTTT – How to Add File from RSS Item’s URL to Dropbox

dropboxif-this-then-thatrss

I'm trying to setup a recipe to download a torrent file automatically to my Dropbox. Pretty much like this one but with another RSS source.

This recipe works fine if the entryUrl is a direct download link. But if the entryUrl is using redirection it only downloads a strange binary file. The extension is good but the added file is corrupted and can't be used.

Is anyone getting such a behaviour and knows a workaround?

Best Answer

Ok here is what I've done :

(solution for developpers. Needs a php server.)

I've writen a PHP script that get the file through redirection (using cURL) and return it. It's another kind of redirection, but it works well with ifttt.

<?PHP
    //get url parameter
    $url = $_GET['url'];



    // send the right headers
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Transfer-Encoding: binary');
    header('Connection: Keep-Alive');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    header('Content-Disposition: attachment; filename="toDownload.torrent"');


    //then download the new file using curl to follow redirection :
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // Important 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 50);

    $st = curl_exec($ch);
    curl_close($ch);

    exit;
?>

Then I've used Yahoo pipes to modify the torrent RSS feed so each link becomes :

http:// [my.server.url]/thisscript.php?url=http:// the.redirect.url/324pfokT5

it makes ifttt believe its not a redirection and download the good file ! :)