To use Amazon S3 with Gaufrette using the recommended SDK v3, follow these steps:
- Install the SDK: Run
composer require aws/aws-sdk-php:^3.0. - Define the S3 Client Service: Register the
Aws\S3\S3Client in your Symfony services configuration using its factory method. - Configure Gaufrette: Reference the service ID in your
knp_gaufrette configuration.
Note: Ensure your bucket is located in the correct region. S3 bucket names containing dots (e.g., com.mycompany.bucket) may cause issues with some SDK versions; using hyphens (e.g., com-mycompany-bucket) is safer.
composer require aws/aws-sdk-php:^3.0
# 1. Service definition
services:
acme.aws_s3.client:
class: Aws\S3\S3Client
factory: [Aws\S3\S3Client, 'factory']
arguments:
-
version: latest
region: %amazon_s3.region%
credentials:
key: %amazon_s3.key%
secret: %amazon_s3.secret%
# 2. Gaufrette configuration
knp_gaufrette:
adapters:
profile_photos:
aws_s3:
service_id: 'acme.aws_s3.client'
bucket_name: 'images'
detect_content_type: true
options:
directory: 'profile_photos'