user3027693
user3027693

Reputation: 31

Display images uploaded on amazon S3 with symfony2

Which is the best practice to show images from a remote amazon s3 repos on a symfony2 project?

I used KnpGaufretteBundle to upload the images on Amazon.

Upvotes: 2

Views: 2429

Answers (1)

Chase
Chase

Reputation: 9362

Sure, you would want to use the AWS SDK for PHP and then you will be able to access all the files in a given S3 drirectory. Then pass those to twig so you can render them.

S3 Usage Documentation

use Aws\S3\S3Client;

...

public function gallaryAction(){
    $client = S3Client::factory(array(
        'key'    => '<aws access key>',
        'secret' => '<aws secret key>'
    ));

   $images = $client->getIterator('ListObjects', array(
        'Bucket' => $bucket,
        'Marker' => 'folder1/gallary/',
        //I believe marker is what would be use to say only objects in this folder. Not 100% on that.
   ));

    return $this->render('twig_template_name.html.twig',array('images'=> $images));
}

Then you would just use the images in your twig file to create the s3 link.

Upvotes: 2

Related Questions