Kim Stacks
Kim Stacks

Reputation: 10822

How to use Gaufrette to upload and store an image into S3 without using the bundle?

I found this http://knplabs.com/blog/give-your-projects-a-gaufrette

and the code sample it provides is

<?php

$amazon = new AmazonS3('myKey', 'mySecretKey', 'myToken');
$adapter = new Gaufrette\Adapter\AmazonS3($amazon, 'my_bucket');
$filesystem = new Gaufrette\Filesystem($adapter);

if ( ! $filesystem->has('foo')) {
    $filesystem->write('foo', 'Some content');
}

echo $filesystem->read('foo');

This does not appear to be writing an image file.

I also found Gaufrette upload image and store in AmazonS3

but the answer appears to be leaning towards using Gaufrette bundle for Symfony.

I am not using Symfony, so I am hoping for a good example I can use to upload images to S3 via Gaufrette.

Thank you.

Upvotes: 1

Views: 4597

Answers (1)

Andresch Serj
Andresch Serj

Reputation: 37378

Your example writes the text "Some content". Instead of that you could put your image content.

$imageData = file_get_contents('/tmpupload/picture.jpeg');
$filesystem->write('foo', $imageData);

You should also write the images mime type to amazon/gaufrette. If i am not mistaken, this should work:

$filesystem->write('foo', $imageData, ['content-type' => 'image/jpeg']);

Upvotes: 2

Related Questions