cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We love to hear how every person gets the most from Dropbox, and it seems everyone has a slightly different use for it - tell us yours 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: 

Ziping 1GB folder and downloading it as client

Ziping 1GB folder and downloading it as client

MarekKonderla
New member | Level 2

Hi, I have been experimenting with dropbox api on my PHP project and everything is working fine, until I try download bigger folders (cca 1GB). The downloadZip method from SDK is returning a huge body, which cannot be printed (due to memory limit), so I have used fpassthru and succesfully downloaded zip as client, but there is a still huge amount of time consumed by the act of server downloading the response, which brings me to my question.

 

Is there a possibility in node js or php to start downloading file while script fetches data from dropbox? 

 

Basically I would to start downloading instantly, but I am not even sure if it is possible.

 

I am also open to other solutions

1 Reply 1

Re: Ziping 1GB folder and downloading it as client

MarekKonderla
New member | Level 2

So I have found a solution. 

 

Example:

header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition:attachment;filename=" . $album->name . '.zip');

$opts = [
    'http' => [
        'method' => "POST",
        'header' => "Authorization: Bearer TOKEN\r\n" .
            "Dropbox-API-Arg: ".json_encode([
                "path" => $path
            ])."\r\n",
        'body' => ''
    ]
];

$context = stream_context_create($opts);
$fp = fopen('https://content.dropboxapi.com/2/files/download_zip', 'r', false, $context);
fpassthru($fp);
exit();

 Which essentialy streams output of dropbox endpoint directly to a client, without a need to store it to memory.

Who's talking

Top contributors to this post

  • User avatar
    MarekKonderla New member | Level 2
What do Dropbox user levels mean?
Need more support?