cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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

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.

Need more support?
Who's talking

Top contributors to this post

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