ffogarasi / s3-bucket-stream-zip-php
PHP library to efficiently stream contents from an AWS S3 bucket or folder as a zip file
Installs: 2 466
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 16
Open Issues: 0
Requires
- php: >=5.3.3
- aws/aws-sdk-php: 3.*
- maennchen/zipstream-php: 0.3.*
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is not auto-updated.
Last update: 2024-11-15 21:59:26 UTC
README
Forked from Michaeltlee/s3-bucket-stream-zip-php
Overview
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
Installation is done via composer by adding the a dependency on .
composer require ffogarasi/s3-bucket-stream-zip-php
Usage
// 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');
Laravel 5.4
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
.
OR in config/app.php
'providers' => [ ... MTL\S3BucketStreamZip\AWSZipStreamServiceProvider::class, ... ]
in config/services.php
, set:
's3' => [ 'key' => '', 'secret' => '', 'region' => '', 'version' => '', ];
Authors
- Jaisen Mathai jaisen@jmathai.com - http://jaisenmathai.com
Dependencies
- 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