Marcio Mazzucato
Marcio Mazzucato

Reputation: 9305

Resize image with SimpleImage and send it directly to Amazon S3

After upload images i resize them using SimpleImage and send to AWS S3. Today i am saving the images in local disk, sending to S3 and then delete the local files. I would like skip to step do save and delete the local files.

I tried:

$S3->putObject([
    'Bucket' => 'mybucket',
    'Key'    => 'myfile.jpeg',
    'Body'   => (new SimpleImage('/path/to/myfile.jpeg'))
                    ->bestFit(
                        800,
                        600
                    )->toString();
]);

The file is sended, but when i access its public URL at AWS S3, the browser tries to download the file and don't show it.

Any help will be welcome!

Upvotes: 0

Views: 552

Answers (1)

dtmiRRor
dtmiRRor

Reputation: 599

You need to make the object public and add ContentType

$S3->putObject([
    'Bucket'      => 'mybucket',
    'Key'         => 'myfile.jpeg',
    'ContentType' => 'image/jpeg',     // <-- add this line
    'Body'        => (new SimpleImage('/path/to/myfile.jpeg'))
                        ->bestFit(
                            800,
                            600
                      )->toString();
]);

Upvotes: 1

Related Questions