php tus aws s3
1.0.0
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
use TusPhpTusServer as TusServer;
class Server
extends TusServer
{
//...
public function __construct(
TusPhpCacheAbstractCache $cache,
LeagueFlysystemAwsS3v3AwsS3Adapter $storage,
TusPhpS3HttpRequest $request,
$excludeAttrApiPath = [],
$forceLocationSSL = true)
{
//...
}
}
Property | Type | Details |
---|---|---|
$cache |
TusPhpCacheAbstractCache |
We are using TusPhpS3CachePredisCache for Predis client. |
$storage |
LeagueFlysystemAwsS3v3AwsS3Adapter |
This adapter contains the AWS S3 Client. |
$request |
TusPhps3HttpRequest |
This object contain a SymfonyComponentHttpFoundationRequest . |
$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 AwsS3S3Client;
use LeagueFlysystemAwsS3v3AwsS3Adapter;
use SymfonyComponentHttpFoundationRequest as HttpRequest;
class UploadController
{
public function upload()
{
// redis connection
$predis = new PredisClient('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 TusPhpS3Server(
new TusPhpS3CachePredisCache($predis),
new AwsS3Adapter($S3client, 'your-bucket-name', 'optional/path/prefix'),
new TusPhpS3HttpRequest(HttpRequest::createFromGlobals()),
['id'],
true
);
return $server->serve(); // return an TusPhpS3HttpResponse
}
}