rafaeltovar / php-tus-aws-s3
Simple, light, minimum TUS server connected with AWS S3. Based on https://github.com/ankitpokhrel/tus-php
Installs: 3 805
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 3
Open Issues: 1
Requires
- php: >=7.0
- ankitpokhrel/tus-php: ^2.3
- aws/aws-sdk-php: ^3.112
- guzzlehttp/guzzle: ^6.4
- league/flysystem-aws-s3-v3: ^1.0
- psr/container: ^1.0
- symfony/http-foundation: ^5.0 || ^6.0
README
This project is not being maintained. Please use the original project ankitpokhrel/tus-php to ensure regular updates. Here are some notes about using the project with AWS S3.
PHP TUS protocol server for Amazon Web Service S3
Simple, light, minimum TUS server connected with AWS S3. Based on ankitpokhrel/tus-php.
Versions
If you are using Symfony, check the table below.
Symfony Version | php-tus-aws-s3 version |
---|---|
^4.3 | ~1.0 |
^5.0 or ^6.0 | ~1.1 |
Installation
Composer
composer require rafaeltovar/php-tus-aws-s3:~1.x predis/predis
Features
- Implements TUS protocol server for upload files
- AWS S3 multiparts uploads
- Uploads directly to AWS S3
- Use Redis like data cache with Predis
- Flysystem compatible
Documentation
Understanding TusPhpS3\Server class constructor
use TusPhp\Tus\Server as TusServer; class Server extends TusServer { //... public function __construct( TusPhp\Cache\AbstractCache $cache, League\Flysystem\AwsS3v3\AwsS3Adapter $storage, TusPhpS3\Http\Request $request, $excludeAttrApiPath = [], $forceLocationSSL = true) { //... } }
Property | Type | Details |
---|---|---|
$cache |
TusPhp\Cache\AbstractCache |
We are using TusPhpS3\Cache\PredisCache for Predis client. |
$storage |
League\Flysystem\AwsS3v3\AwsS3Adapter |
This adapter contains the AWS S3 Client. |
$request |
TusPhps3\Http\Request |
This object contain a Symfony\Component\HttpFoundation\Request . |
$excludeAttrApiPath |
array |
Exclude some parts from Api path for create a real Api Base Path for TUS Server. For example, if my Api base path is https://example.com/uploads but my upload PATCH is http://example.com/uploads/{id} We need exclude ['id'] . |
$forceLocationSSL |
boolean |
Force location header property to https . |
TUS Routes
/** * Create new upload * or get server configuration **/ $routes->add('uploads', '/api/uploads') ->controller([UploadController::class, 'upload']) ->methods([POST, OPTIONS]) /** * Upload files * or delete uploads **/ $routes->add('uploads', '/api/uploads/{id}') ->controller([UploadController::class, 'upload']) ->methods([PATCH, DELETE])
Running TUS Server
use TusPhpS3; use Aws\S3\S3Client; use League\Flysystem\AwsS3v3\AwsS3Adapter; use Symfony\Component\HttpFoundation\Request as HttpRequest; class UploadController { public function upload() { // redis connection $predis = new Predis\Client('tcp://10.0.0.1:6379'); // AWS S3 Client $S3client = new S3Client([ 'credentials' => [ 'key' => 'your-key', 'secret' => 'your-secret', ], 'region' => 'your-region', 'version' => 'latest|version', ]); $server = new TusPhpS3\Server( new TusPhpS3\Cache\PredisCache($predis), new AwsS3Adapter($S3client, 'your-bucket-name', 'optional/path/prefix'), new TusPhpS3\Http\Request(HttpRequest::createFromGlobals()), ['id'], true ); return $server->serve(); // return an TusPhpS3\Http\Response } }