reconnect/s3bundle

Symfony S3 Bundle

安装: 715

依赖者: 0

建议者: 0

安全性: 0

星标: 4

关注者: 1

分支: 3

开放问题: 1

类型:symfony-bundle

1.3.3 2024-01-09 10:53 UTC

This package is auto-updated.

Last update: 2024-09-09 12:42:00 UTC


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