Installation guide
'debug' => true
));
More control with the UploadSyncBuilder
The uploadDirectory() method is an abstraction layer over the much more powerful
Aws\S3\Sync\UploadSyncBuilder. You can use an UploadSyncBuilder object directly if you need more
control over the transfer. Using an UploadSyncBuilder allows for the following advanced features:
• Can upload only files that match a glob expression
• Can upload only files that match a regular expression
• Can specify a custom \Iterator object to use to yield files to an UploadSync object. This can be used, for
example, to filter out which files are transferred even further using something like the Symfony 2 Finder
component.
• Can specify the Aws\S3\Sync\FilenameConverterInterface objects used to convert Amazon S3
object names to local filenames and vice versa. This can be useful if you require files to be renamed in a
specific way.
use Aws\S3\Sync\UploadSyncBuilder;
UploadSyncBuilder::getInstance()
->setClient($client)
->setBucket('my-bucket')
->setAcl('public-read')
->uploadFromGlob('/path/to/file/*.php')
->build()
->transfer();
Downloading a bucket to a directory
You can download the objects stored in an Amazon S3 bucket using features similar to the uploadDirectory()
method and the UploadSyncBuilder. You can download the entire contents of a bucket using the
Aws\S3\S3Client::downloadBucket() method.
The following example will download all of the objects from my-bucket and store them in /local/directory.
Object keys that are under virtual subfolders are converted into a nested directory structure when downloading the
objects. Any directories missing on the local filesystem will be created automatically.
$client->downloadBucket('/local/directory', 'my-bucket');
Customizing the download sync
The method signature of the downloadBucket() method allows for the following arguments:
public function downloadBucket($directory, $bucket, $keyPrefix = null, array $options = array())
By specifying $keyPrefix, you can limit the downloaded objects to only keys that begin with the specified
$keyPrefix. This, for example, can be useful for downloading objects under a specific virtual directory.
The downloadBucket() method also accepts an optional associative array of $options that can be used to
further control the transfer.
params Array of parameters to use with each GetObject operation performed during the transfer. See
GetObject for a list of available options.
base_dir Base directory to remove from each object key when downloading. By default, the entire object key
is used to determine the path to the file on the local filesystem.
force Set to true to download every file, even if the file is already on the local filesystem and has not
changed.
concurrency Maximum number of parallel downloads (defaults to 10)
Amazon Simple Storage Service
110