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

Compatibility with s3fs to upload to S3 bucket ... #79

Open
sunandang opened this issue Jul 19, 2016 · 4 comments
Open

Compatibility with s3fs to upload to S3 bucket ... #79

sunandang opened this issue Jul 19, 2016 · 4 comments
Labels

Comments

@sunandang
Copy link

Hi -
This is not working if I want to upload images directly into an S3 bucket mounted on my EC2 instance using s3fs.

Have you tested it?

@antonskv
Copy link

I have tried that myself, but s3fs seems to be a bit laggy when you mount a bucket with a huge load of images. I wondered that it might affect server boot time and general performance.

That's why i chose to just do manual AWS S3 API upload inside the Controller. It works fast and not too many issues.

@comur comur added the feature label May 23, 2019
@comur
Copy link
Owner

comur commented May 23, 2019

@sunandang @antonskv
Do you want to add a feature to directly bind the bundle to S3 ? I don't have any case to test so...

@antonskv
Copy link

With requirement of "aws/aws-sdk-php" in composer, you can do this inside upload controller. Obviously inside TRY and CATCH block to see if the upload went through. S3 Client will throw an error on putObject if something is wrong.

/* @var $uploaded_file \Symfony\Component\HttpFoundation\File\UploadedFile */
$uploaded_file = $request->files->get('uploadFile');

$s3key = $this->container->getParameter('comur_image.s3.aws_key');
$s3secret = $this->container->getParameter('comur_image.s3.aws_secret');
$bucket = $this->container->getParameter('comur_image.s3.bucket');
$uploadPath = $this->container->getParameter('comur_image.s3.path');

$client = \Aws\S3\S3Client::factory(['key' => $s3key, 'secret' => $s3secret]);

/** @NOTE: Or whatever other random mechanism to get long UID */
$newFileName = \hash('sha256',  \uniqid()) . ".{$uploaded_file->getClientOriginalExtension()}";
$fullPath = $uploadPath . "/{$newFileName}";

$client->putObject([
                'Bucket' => $bucket,
                'Key'    => $fullPath,
                'SourceFile' => $uploaded_file->getPathname(),
                'ContentType' => $uploaded_file->getMimeType()
            ]);

/** @NOTE: Clean up original file from temp upload directory */
if(\file_exists($uploaded_file->getPathname()))
    \unlink($uploaded_file->getPathname());

Why i commenting with a sample code response, is cause i never actually done a real code contribution to somebody elses' repo in github.... I wouldn't know how. I know it's kind of sad =) LOL

@comur
Copy link
Owner

comur commented May 25, 2019

Hi @antonskv
Thx for your code.
I don’t know if we can add some code with an optionally included package. I will take a look.
For contributing, you just need to fork this repo, push your code on your fork and create a pull request on github from your fork to original repo.
Tell me if you can do it so we can have you between contributors ;)
Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants