reconnect / s3bundle
Symfony S3 Bundle
Installs: 880
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 0
Forks: 3
Open Issues: 0
Type:symfony-bundle
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 helps you connect you Symfony application to a S3 bucket, or any bucket that implements S3 API. It is a wrapper
around the great league/flysystem-aws-s3-v3
library
Installation
composer require reconnect/s3bundle
If you are not using Symfony flex, you will need a few extra steps to enable and configure the bundle
Usage
You need to update the following environment variables to make this bundle works
BUCKET_HOST=http://localhost:9000/ // For a local bucket for example BUCKET_NAME=files BUCKET_KEY=files_access BUCKET_SECRET=files_secret
Then, you can inject the FlysystemS3Client.php
to do some common operations on buckets, such as :
Fetching a document presigned 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);
Posting a document
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);
Generating a thumbnail
You can also generate a thumbnail, it handles images and pdfs
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);
Configuration reference
# Default configuration for extension with alias: "reconnect_s3_bundle" reconnect_s3_bundle: bucketHost: ~ # Required bucketName: ~ # Required bucketKey: ~ # Required bucketSecret: ~ # Required