reconnect / s3bundle
Symfony S3 Bundle
1.3.3
2024-01-09 10:53 UTC
Requires
- php: >=7.4.0
- ext-exif: *
- ext-fileinfo: *
- ext-imagick: *
- league/flysystem-aws-s3-v3: ^2.0|^3.0
- symfony/config: ^4.4|^5.4|^6.0|^7.0
- symfony/dependency-injection: ^4.4|^5.4|^6.0|^7.0
- symfony/http-foundation: ^4.4|^5.4|^6.0|^7.0
- symfony/http-kernel: ^4.4|^5.4|^6.0|^7.0
- symfony/mime: ^4.4|^5.4|^6.0|^7.0
- symfony/string: ^4.4|^5.4|^6.0|^7.0
- symfony/uid: ^4.4|^5.4|^6.0|^7.0
README
S3Bundle 帮助您将您的 Symfony 应用连接到 S3 存储桶或任何实现 S3 API 的存储桶。它是围绕优秀的 league/flysystem-aws-s3-v3 库的一个包装器。
安装
composer require reconnect/s3bundle
如果您不使用 Symfony flex,您需要一些额外的步骤来启用和配置此包。
使用
您需要更新以下环境变量以使此包正常工作:
BUCKET_HOST=https://:9000/ // For a local bucket for example BUCKET_NAME=files BUCKET_KEY=files_access BUCKET_SECRET=files_secret
然后,您可以注入 FlysystemS3Client.php 来对存储桶执行一些常见操作,例如:
获取文档预签名 URL
use Reconnect\S3Bundle\Service\FlysystemS3Client; // ... private FlysystemS3Client $S3Client; public function __construct(FlysystemS3Client $s3Adapter) { $this->documentService = $S3Client; } // ... // The $objectKey is the key we used to identify the file in the bucket $presignedUrl = $S3Client->getPresignedUrl($objectKey);
上传文档
use Reconnect\S3Bundle\Service\FlysystemS3Client; // ... private FlysystemS3Client $S3Client; public function __construct(FlysystemS3Client $s3Adapter) { $this->documentService = $S3Client; } // ... // Get a file as an instance of File // This method returns the key of the uploaded file in the bucket // This $key is a random UuidV4 $key = $S3Client->uploadFile($file);
生成缩略图
您也可以生成缩略图,它可以处理图片和 PDF。
use Reconnect\S3Bundle\Service\FlysystemS3Client; // ... private FlysystemS3Client $S3Client; public function __construct(FlysystemS3Client $s3Adapter) { $this->documentService = $S3Client; } // ... // Get a file as an instance of UploadedFile // This method returns the key of the uploaded thumbnail file in the bucket // This $key is a random UuidV4 $thumbnailKey = $S3Client->generateThumbnail($file);
配置参考
# Default configuration for extension with alias: "reconnect_s3_bundle" reconnect_s3_bundle: bucketHost: ~ # Required bucketName: ~ # Required bucketKey: ~ # Required bucketSecret: ~ # Required