contextualcode/ezplatform-aws-s3-adapter
Installation Add the package via Composer:
composer require contextualcode/ezplatform-aws-s3-adapter
Configuration Publish the package config:
php artisan vendor:publish --provider="ContextualCode\EzPlatformAwsS3Adapter\EzPlatformAwsS3AdapterServiceProvider" --tag="config"
Update config/ezplatform-aws-s3-adapter.php with your AWS credentials and bucket settings:
'buckets' => [
'default' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'bucket' => env('AWS_S3_BUCKET'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
],
First Use Case: File Upload Inject the adapter into a service or controller:
use ContextualCode\EzPlatformAwsS3Adapter\S3FileAdapter;
public function __construct(S3FileAdapter $s3Adapter) {
$this->s3Adapter = $s3Adapter;
}
public function uploadFile($filePath, $destinationPath) {
$this->s3Adapter->save($filePath, $destinationPath);
}
File Operations
$this->s3Adapter->save($localPath, $s3Path); // Upload
$this->s3Adapter->load($s3Path, $localPath); // Download
streamSave() and streamLoad() to handle large files without memory issues:
$this->s3Adapter->streamSave($localPath, $s3Path);
Integration with eZ Platform
config/ezplatform.yml:
system:
site:
file_system:
default: s3
ezplatform-aws-s3-adapter for custom field types (e.g., ezplatform-aws-s3-adapter:file in field type definitions).URL Generation
$url = $this->s3Adapter->getUrl($s3Path, '+1 hour');
$adapter = new S3FileAdapter('custom_bucket');
FileSystemEvents (e.g., FileSystemCreated, FileSystemDeleted) for post-upload actions:
$this->events->listen(
\EzSystems\PlatformHttpCache\Event\FileSystemCreatedEvent::class,
function ($event) {
// Log or process the uploaded file
}
);
Permissions
s3:PutObject, s3:GetObject, and s3:DeleteObject permissions.aws s3 ls or the AWS CLI.CORS Configuration
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Path Handling
save()/load() calls.$normalizedPath = strtolower($s3Path);
Large File Timeouts
max_execution_time or use streaming:
ini_set('max_execution_time', 300); // 5 minutes
debug: true in the config to log AWS SDK errors:
'debug' => env('APP_DEBUG', false),
\Aws\setLogger(new \Monolog\Logger('aws'));
Custom Metadata Add metadata during upload:
$this->s3Adapter->save($localPath, $s3Path, [
'ContentType' => 'image/jpeg',
'CacheControl' => 'max-age=31536000',
]);
Lifecycle Policies Use S3 lifecycle rules (via AWS Console) to auto-archive or delete old files.
Custom Storage Classes
Override the default storage class (e.g., STANDARD_IA):
$this->s3Adapter->save($localPath, $s3Path, [], 'STANDARD_IA');
S3Client directly for bulk operations (e.g., multiUpload):
$s3 = $this->s3Adapter->getClient();
$result = $s3->createMultiPartUpload(['Bucket' => $bucket, 'Key' => $key]);
How can I help you explore Laravel packages today?