Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to download folder as zip file #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Dropbox/Dropbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,42 @@ public function download($path, $dropboxFile = null)
return new File($metadata, $contents);
}

/**
* Download a folder as a zip file
*
* @param string $path Path to the file you want to download
* @param null|string|DropboxFile $dropboxFile DropboxFile object or Path to target file
*
* @return \Kunnu\Dropbox\Models\File
*
* @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
*
* @link https://www.dropbox.com/developers/documentation/http/documentation#files-download_zip
*
*/
public function downloadZip($path, $dropboxFile = null)
{
//Path cannot be null
if (is_null($path)) {
throw new DropboxClientException("Path cannot be null.");
}

//Make Dropbox File if target is specified
$dropboxFile = $dropboxFile ? $this->makeDropboxFile($dropboxFile, null, null, DropboxFile::MODE_WRITE) : null;

//Download File
$response = $this->postToContent('/files/download_zip', ['path' => $path], null, $dropboxFile);

//Get file metadata from response headers
$metadata = $this->getMetadataFromResponseHeaders($response);

//File Contents
$contents = $dropboxFile ? $this->makeDropboxFile($dropboxFile) : $response->getBody();

//Make and return a File model
return new File($metadata, $contents);
}

/**
* Get Current Account
*
Expand Down