fightstarr20
fightstarr20

Reputation: 12568

Laravel 5.5 - Store image to S3

I am currently writing images created by ImageMagick to local storage in a Laravel 5.5 app like this...

$imagick->writeImages(storage_path('app/files/' . $tempfoldername . '_' . $title . '/' . $title . '_page.jpg'), false);

I have now setup an S3 bucket on AWS to store image to instead, how can i modify the above statement to store them in the bucket instead?

I have already set Laravel up with the S3 details and can successfully read and write to the S3 bucket.

Should I do as I am doing and move them afterwards? Or can I do it directly from that imagemagick statement?

Upvotes: 3

Views: 1563

Answers (1)

ahmad
ahmad

Reputation: 2729

Since you're processing the image using image magick, You have 2 options:

  • First option Store the image in the local folder, then upload, then unlink

    Storage::disk('s3')->put($title . '_page.jpg', new File($filePath));

    unlink($filePath);

  • Or add the image directly to s3 using the following

    Storage::disk('s3')->put($title . '_page.jpg', $imagick->getImageBlob());

Upvotes: 4

Related Questions