Top Related Projects
Abstraction for local and remote filesystems
Official repository of the AWS SDK for PHP (@awsforphp)
Quick Overview
Flysystem-aws-s3-v3 is a PHP package that provides an AWS S3 adapter for the Flysystem filesystem abstraction library. It allows developers to interact with Amazon S3 storage using a consistent API, making it easier to work with cloud storage in PHP applications.
Pros
- Seamless integration with Flysystem, providing a unified interface for various storage systems
- Supports AWS S3 features like presigned URLs and multipart uploads
- Easy to use and configure with minimal setup required
- Actively maintained and compatible with the latest versions of Flysystem and AWS SDK
Cons
- Requires knowledge of Flysystem's architecture and concepts
- Limited to AWS S3 storage; not suitable for other cloud storage providers
- Dependency on the AWS SDK for PHP, which may increase the project's overall size
- May have a slight performance overhead compared to direct AWS SDK usage
Code Examples
- Creating an S3 adapter and filesystem:
use Aws\S3\S3Client;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
$client = new S3Client([
'credentials' => [
'key' => 'your-key',
'secret' => 'your-secret',
],
'region' => 'your-region',
'version' => 'latest',
]);
$adapter = new AwsS3V3Adapter($client, 'your-bucket-name');
$filesystem = new Filesystem($adapter);
- Writing and reading a file:
$filesystem->write('path/to/file.txt', 'Contents of the file');
$contents = $filesystem->read('path/to/file.txt');
echo $contents; // Outputs: Contents of the file
- Generating a presigned URL:
$adapter = $filesystem->getAdapter();
$expiration = new \DateTime('+1 hour');
$url = $adapter->getPresignedUrl('path/to/file.txt', $expiration);
echo $url; // Outputs: https://your-bucket.s3.amazonaws.com/path/to/file.txt?...
Getting Started
-
Install the package via Composer:
composer require league/flysystem-aws-s3-v3
-
Create an S3 client and configure the adapter:
use Aws\S3\S3Client; use League\Flysystem\AwsS3V3\AwsS3V3Adapter; use League\Flysystem\Filesystem; $client = new S3Client([ 'credentials' => [ 'key' => 'your-key', 'secret' => 'your-secret', ], 'region' => 'your-region', 'version' => 'latest', ]); $adapter = new AwsS3V3Adapter($client, 'your-bucket-name'); $filesystem = new Filesystem($adapter);
-
Start using the filesystem:
$filesystem->write('file.txt', 'Hello, World!'); $contents = $filesystem->read('file.txt');
Competitor Comparisons
Abstraction for local and remote filesystems
Pros of Flysystem
- More versatile, supporting multiple storage adapters beyond just AWS S3
- Provides a unified API for various file storage systems
- Easier to switch between different storage providers
Cons of Flysystem
- Larger codebase, potentially more complex to implement
- May have slightly higher overhead due to abstraction layer
- Requires additional adapters for specific storage providers
Code Comparison
Flysystem (generic usage):
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
$adapter = new LocalFilesystemAdapter('/path/to/root');
$filesystem = new Filesystem($adapter);
$filesystem->write('path/to/file.txt', 'contents');
Flysystem-aws-s3-v3 (S3-specific usage):
use Aws\S3\S3Client;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
$client = new S3Client([/* ... */]);
$adapter = new AwsS3V3Adapter($client, 'bucket-name');
$filesystem = new Filesystem($adapter);
$filesystem->write('path/to/file.txt', 'contents');
The main difference is in the adapter setup, while the actual usage remains similar. Flysystem provides a consistent interface across different storage systems, whereas Flysystem-aws-s3-v3 is specifically tailored for AWS S3 integration.
Official repository of the AWS SDK for PHP (@awsforphp)
Pros of aws-sdk-php
- Comprehensive coverage of AWS services beyond just S3
- Direct integration with AWS, providing access to the latest features
- Extensive documentation and community support
Cons of aws-sdk-php
- Steeper learning curve due to its broader scope
- Larger footprint and potential overhead for projects only needing S3 functionality
- May require more configuration and setup for basic S3 operations
Code Comparison
flysystem-aws-s3-v3:
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
$adapter = new AwsS3V3Adapter($client, 'bucket-name');
$filesystem = new Filesystem($adapter);
$filesystem->write('file.txt', 'contents');
aws-sdk-php:
use Aws\S3\S3Client;
$s3 = new S3Client([/* config */]);
$s3->putObject([
'Bucket' => 'bucket-name',
'Key' => 'file.txt',
'Body' => 'contents',
]);
The flysystem-aws-s3-v3 adapter provides a more abstracted and filesystem-like interface, while aws-sdk-php offers direct access to S3 operations with more granular control. The choice between them depends on project requirements, existing infrastructure, and developer preferences.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Sub-split of Flysystem for AWS S3.
â ï¸ this is a sub-split, for pull requests and issues, visit: https://github.com/thephpleague/flysystem
composer require league/flysystem-aws-s3-v3
View the documentation.
Top Related Projects
Abstraction for local and remote filesystems
Official repository of the AWS SDK for PHP (@awsforphp)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot