gaufrette/aws-s3-adapter
Gaufrette AWS S3 adapter provides an Amazon S3 filesystem adapter for the Gaufrette PHP filesystem abstraction library, letting you store and retrieve files on S3 through a consistent, testable filesystem interface with configurable buckets, prefixes, and client options.
Storage::disk('s3') / Flysystem path is almost always the better day-to-day choice. Use this package only if you already have Gaufrette-based code or a legacy integration.gaufrette/aws-s3-adapter, knplabs/gaufrette, and aws/aws-sdk-php resolve under your PHP/Laravel version:
composer require gaufrette/aws-s3-adapter aws/aws-sdk-php
composer show gaufrette/aws-s3-adapter
If Composer pulls an old AWS SDK or conflicts with Laravel’s Flysystem dependencies, stop and use Laravel’s native S3 disk instead.vendor/gaufrette/aws-s3-adapter/src/AwsS3.php for the exact constructor signature.Filesystem API (read, write, exists, delete, listKeys, etc.).config/filesystems.php S3 disk for bucket/region/credentials, so you do not duplicate env configuration.use Aws\S3\S3Client;
use Gaufrette\Adapter\AwsS3;
use Gaufrette\Filesystem;
$s3 = new S3Client([
'version' => 'latest',
'region' => config('filesystems.disks.s3.region'),
'credentials' => [
'key' => config('filesystems.disks.s3.key'),
'secret' => config('filesystems.disks.s3.secret'),
],
]);
// Confirm constructor args in the installed adapter version.
$adapter = new AwsS3($s3, config('filesystems.disks.s3.bucket'), 'imports');
$filesystem = new Filesystem($adapter);
$filesystem->write('example.txt', 'hello');
$contents = $filesystem->read('example.txt');
Gaufrette\Filesystem or a domain-specific wrapper as a singleton, keyed by bucket/prefix. Avoid constructing S3 clients throughout controllers and jobs.Gaufrette\Filesystem everywhere. Create DocumentStorage, UploadStorage, or similar with methods like store(), get(), delete(), exists(). This keeps Gaufrette replaceable.$this->app->singleton('storage.uploads', function ($app) {
$client = new S3Client([...]);
return new Filesystem(new AwsS3($client, $bucket, 'uploads'));
});
filesystems.disks.s3 values for bucket, region, endpoint, and credentials. In production prefer IAM roles/instance profiles over long-lived keys.tenants/{tenant_id}/documents/. Normalize keys before writing.S3Client:
$cmd = $s3->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => 'uploads/example.pdf',
]);
$url = (string) $s3->createPresignedRequest($cmd, '+15 minutes')->getUri();
write() takes a string, so avoid loading large files into memory.Filesystem instances. Rebuild or resolve the filesystem inside the job. This keeps payloads serializable and avoids stale credentials.use Gaufrette\Adapter\InMemory;
use Gaufrette\Filesystem;
$this->app->instance('storage.uploads', new Filesystem(new InMemory()));
If you need to test S3-specific behavior, mock S3Client or use a local S3-compatible service such as MinIO.Storage::disk(), Storage::fake(), or Laravel’s filesystem macros. If you need Laravel-native APIs, use Flysystem/Laravel Storage instead.S3Client, bucket, prefix, and options in that order. Do not assume support for ACLs, storage classes, content types, or custom endpoints.exists()/read() with exact keys.keys()/listKeys() over a large bucket can be slow and expensive. For large inventories, use the AWS SDK paginator directly and filter by prefix.Aws\Exception\AwsException. Catch both at the boundary and log the S3 error code/request ID.s3:GetObject, s3:PutObject, s3:DeleteObject, and s3:ListBucket scoped to the bucket/prefix. Multipart uploads may also need abort permissions.endpoint, use_path_style_endpoint, and region correctly on S3Client. The Gaufrette adapter may not expose all client options.write() to set Content-Type or public-read automatically unless the adapter version supports it.AwsException messages, and verify with a direct headObject() call. Laravel logs alone often hide the S3 request ID.env(), run php artisan config:cache consistently and remember queue workers may need restarts after config changes. Prefer IAM roles in production to reduce credential handling.How can I help you explore Laravel packages today?