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.
Simple, light, minimum TUS server connected with AWS S3. Based on ankitpokhrel/tus-php.
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 |
composer require rafaeltovar/php-tus-aws-s3:~1.x predis/predis
- 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
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 . |
/**
* 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])
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
}
}