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.

Discuss Dropbox Developer & API

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

Re: download_zip api

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"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); curl_close($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { $file_name = $file_name . '.zip'; file_put_contents(get_home_path() . '/' . $file_name, $result); $zipFilePath = get_home_path() . $file_name; $zipBaseName = basename($zipFilePath); header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=$zipBaseName"); header("Content-Length: " . filesize($zipFilePath)); readfile($zipFilePath); @unlink($zipFilePath); die(); } }

here is my code, but it only works on a local server, on a real site it produces such an error, why? https://monosnap.com/file/0Dxbpzchbiq8ngZRl42SNEHqbCvmi1

4 Replies 4

Greg-DB
Dropbox Staff

To clarify, is the screenshot you shared showing the rendering of some HTML returned by https://content.dropboxapi.com/2/files/download_zip?

Can you share what the rest of the response is, that is, the response status and headers?

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

i have to return zip archive data but it returns https://monosnap.com/file/0Dxbpzchbiq8ngZRl42SNEHqbCvmi1

Greg-DB
Dropbox Staff

Thanks, but still to clarify, what exactly are you doing to get the result in that second screenshot? That appears to be a Dropbox HTML error page, but the response in the first screenshot indicates that the response was just plain text, not HTML.

That 400 response should indicate that the API request wasn't correctly formatted. The plain text response body should be a more useful error message, so please print that out, e.g., like `echo $result;`.

Need more support?