Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of the cloud providers storages #178

Merged
merged 1 commit into from
Aug 17, 2019
Merged

Add support of the cloud providers storages #178

merged 1 commit into from
Aug 17, 2019

Conversation

francoispluchino
Copy link
Contributor

@francoispluchino francoispluchino commented Aug 14, 2019

Currently, TUS PHP does not work with stream wrappers from cloud providers such as AWS S3.

This pull request makes TUS PHP compatible with stream wrappers and cloud providers storages.

Regarding DIRECTORY_SEPARATOR, there is no need to use (for this use case) it since Windows handles the slash for directories very well.

Regarding APPEND_BINARY, the cloud provider storages can only open a read or write stream, but not both.

@samundra
Copy link
Collaborator

Hi @francoispluchino

Is there any easier way to verify that the changes work as expected?

A step by step guideline or simple how-to would be nice.

@francoispluchino
Copy link
Contributor Author

AWS S3 Bucket

  1. Create an AWS account
  2. Connect to the AWS Console
  3. Open the S3 service
  4. Create your bucket (and keep the bucket name for after)
  5. Create a server app

Server app

Install the deps

composer init -n
composer require ankitpokhrel/tus-php aws/aws-sdk-php

Create the server.php file

touch server.php
<?php

require 'vendor/autoload.php';

use Aws\S3\S3Client;
use Aws\Credentials\Credentials;
use TusPhp\Tus\Server;

$awsAccessKey = 'AWS_ACCESS_KEY';// YOUR AWS ACCESS KEY
$awsSecretKey = 'AWS_SECRET_KEY';// YOUR AWS SECRET KEY
$awsRegion = 'eu-west-1';// YOUR AWS BUCKET REGION
$basePath = 's3://your-bucket-name';// YOUR BUCKET NAME

$s3Client = new S3Client([
    'version' => 'latest',
    'region' => $awsRegion,
    'credentials' => new Credentials($awsAccessKey, $awsSecretKey)
]);
$s3Client->registerStreamWrapper();

$server = new Server('file');
$server->setUploadDir($basePath);

$response = $server->serve();
$response->send();

exit(0);

Copy link
Owner

@ankitpokhrel ankitpokhrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ankitpokhrel ankitpokhrel merged commit 34bf866 into ankitpokhrel:master Aug 17, 2019
@francoispluchino
Copy link
Contributor Author

Thank you

@ankitpokhrel ankitpokhrel added this to the Unreleased milestone Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants