cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Ross uses Dropbox to answer some new house questions 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 3

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

Re: download_zip api

Greg-DB
Dropboxer

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?

Re: download_zip api

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

Re: download_zip api

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

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

Re: download_zip api

Greg-DB
Dropboxer

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;`.

Who's talking

Top contributors to this post

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