nextsourcia / s3-bucket-stream-zip-php
PHP 库,用于高效地将 AWS S3 桶或文件夹的内容作为 zip 文件流式传输
v1.0
2019-12-20 14:21 UTC
Requires
- php: >=5.3.3
- aws/aws-sdk-php: 3.*
- maennchen/zipstream-php: 0.3.*
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is auto-updated.
Last update: 2024-09-12 23:51:51 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' => '*****', //optional
'secret' => '*****', //optional
'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
并复制examples/AwsZipStreamServiceProvider.php
的内容。- 确保所有配置值都已设置。
- 在
config/app.php
中注册提供者。
或者在 config/app.php
'providers' => [
...
MTL\S3BucketStreamZip\AWSZipStreamServiceProvider::class,
...
]
在 config/services.php
中设置
'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