Forked from jmathai/s3-bucket-stream-zip-php
This library lets you efficiently stream the contents of an S3 bucket/folder as a zip file to the client.
Uses v3 of AWS SDK to stream files directly from S3.
Installation is done via composer by adding the a dependency on .
composer require michaeltlee/s3-bucket-stream-zip-php
// taken from examples/simple.php
// since large buckets may take lots of time we remove any time limits
set_time_limit(0);
require sprintf('%s/../vendor/autoload.php', __DIR__);
use Aws\S3\Exception\S3Exception;
use MTL\S3BucketStreamZip\Exception\InvalidParameterException;
use MTL\S3BucketStreamZip\S3BucketStreamZip;
$auth = [
'key' => '*****',
'secret' => '*****',
'region' => 'us-east-1', // optional. defaults to us-east-1
'version' => 'latest' // optional. defaults to latest
];
$stream = new S3BucketStreamZip($auth);
try {
$stream->bucket('testbucket')
->prefix('testfolder') // prefix method adds a trailing '/'
->send('name-of-zipfile-to-send.zip');
} catch (InvalidParameterException $e) {
// handle the exception
echo $e->getMessage();
} catch (S3Exception $e) {
// handle the exception
echo $e->getMessage();
}
$stream->bucket('another-test-bucket')
->prefix('test/')
->addParams([
'MaxKeys' => 1, // array of other parameters
])
->send('zipfile-to-send.zip');
// if prefix is not supplied, entire bucket contents are streamed
$stream->bucket('another-test-bucket')
->send('zipfile-to-send.zip');
pa make:provider AWSZipStreamServiceProvider
and copy the contentsexamples/AwsZipStreamServiceProvider.php
.- Make sure your config values are all set.
- Register the provider in
config/app.php
.
'providers' => [
...
MTL\S3BucketStreamZip\AWSZipStreamServiceProvider::class,
...
]
in config/services.php
, set:
's3' => [
'key' => '',
'secret' => '',
'region' => '',
'version' => '',
];
- Jaisen Mathai jaisen@jmathai.com - http://jaisenmathai.com
- Paul Duncan pabs@pablotron.org - http://pablotron.org/
- Jonatan Männchen jonatan@maennchen.ch - http://commanders.ch
- Jesse G. Donat donatj@gmail.com - https://donatstudios.com