cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Whether you are transferring a single drive, a team or an entire organization, Movebot's cloud migration tool has been built to make your Dropbox migration simple - learn all about it here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

download_zip api

download_zip api

Андрей Г.2
Explorer | Level 4

please give me an example of working code on php for download_zip, I unfortunately did not find this

5 Replies 5

Re: download_zip api

Greg-DB
Dropboxer

I don't have a sample of calling /2/files/download_zip in PHP in particular to share. The documentation has an example of calling it using command line curl though. Likewise, the API v2 Explorer can build sample code for it in a few formats. You can use those as a reference to write your code on your platform using whatever HTTPS client you're using.

Re: download_zip api

Андрей Г.2
Explorer | Level 4

the problem is that in the example it works, and I often get allowed memory size of bytes exhausted. I need some good sdk

Re: download_zip api

Greg-DB
Dropboxer

We don't have an official PHP SDK for Dropbox API v2, but another option is to use a third party library. We have some listed here:

https://www.dropbox.com/developers/documentation/communitysdks

I don't know which, if any, of those happen to implement /2/files/download_zip though.

Re: download_zip api

Андрей Г.2
Explorer | Level 4
function dropbox_download_zip($folder_path, $file_name)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/download_zip');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = "Authorization: Bearer " . DROPBOX_TOKEN . "";
    $headers[] = "Dropbox-API-Arg: {\"path\": \"$folder_path\"}";
    $headers[] = "Content-Type: application/octet-stream; charset=utf-8";
    $headers[] = "User-Agent: api-explorer-client";
    $headers[] = "Content-Length: 0";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    } else {
        $zip_file_name = $file_name . '.zip';

        header('Content-type: application/zip');
        header('Content-Disposition: attachment; filename=' . $zip_file_name);
        header('Content-Length: ' . strlen($result));
        echo $result;


        die();
    }
}

I have this code but for large files (eg 300mb) there is an error 'allowed memory size of bytes exhausted', I think it is due to the large file size,
please tell me how you can make curl result immediately written to zip file

Re: download_zip api

Greg-DB
Dropboxer

I can't really help with memory management on your system or with configuring third party clients as they're not made by Dropbox. That said, if you want to use curl to save to a local file on your server's local filesytem, you may want to use the 'CURLOPT_FILE' option.

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    Андрей Г.2 Explorer | Level 4
What do Dropbox user levels mean?
Need more support?