We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Андрей Г.2
6 years agoExplorer | Level 4
Dropbox download_zip api
I use api https://www.dropbox.com/developers/documentation/http/documentation#files-download_zip to download files from a folder, but I always get an error in call to API function "files / download_z...
Greg-DB
Dropbox Community Moderator
6 years agoThanks for the additional information. I see you have extra \ values in your JSON string. You may have copied those from the command-line curl examples in the documentation. Those are only needed in contexts where you need to escape the subsequent " values, such as in bash, like in those examples, since the " character is already used to start the string for the header parameter for curl itself.
Since that doesn't apply to your PHP context, you shouldn't include them as they'll be sent as-is, corrupting the JSON string. Instead, you'd just want something like:
$headers[] = 'Dropbox-Api-Arg: {"path": "/test"}';
I do recommend having some other library or method build those JSON strings for you instead though.
polishchyk-a-v
6 years agoExplorer | 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
- Greg-DB6 years ago
Dropbox Community Moderator
I see this was also opened as a new thread, so I'll take a look and reply on that one:
https://www.dropboxforum.com/t5/Discuss-Developer-API/download-zip-api/m-p/392520#M963
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!