ffogarasi/s3-bucket-stream-zip-php

PHP library to efficiently stream contents from an AWS S3 bucket or folder as a zip file

4.0.1 2017-07-25 13:17 UTC

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 contents examples/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

Dependencies