michaeltlee/s3-bucket-stream-zip-php

PHP 库,用于高效地将 AWS S3 存储桶或文件夹的内容作为 zip 文件流式传输

v4.0.0 2017-03-13 17:42 UTC

This package is not auto-updated.

Last update: 2024-09-18 18:48:11 UTC


README

jmathai/s3-bucket-stream-zip-php 分支而来

概览

此库允许您将 S3 存储桶/文件夹的内容作为 zip 文件高效地流式传输到客户端。

使用 AWS SDK 的第 3 版直接从 S3 流式传输文件。

安装

安装通过 composer 完成,通过添加依赖项。

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');

Laravel 5.4

  • php artisan make:provider AWSZipStreamServiceProvider 并复制 examples/AwsZipStreamServiceProvider.php 的内容。
  • 确保您的配置值都已设置。
  • config/app.php 中注册提供者。

或者,在 config/app.php

'providers' => [
    ...
    MTL\S3BucketStreamZip\AWSZipStreamServiceProvider::class,
    ...
]

中,在 config/services.php 中设置

's3' => [
    'key'     => '', 
    'secret'  => '', 
    'region'  => '',
    'version' => '',
];

作者

依赖项