Laravel Intervention image upload to Amazon S3
Hi,
WHen I use the code below to resize an image with intervention image and then upload it to S3:
$image = Image::make(request()->file('image'))->resize(400, 300);
$path = Storage::disk('s3')->put('/public/items/test.jpg', $image->__toString());
Then the file is created in my S3 bucket but the file is empty (size 0 kb).
What am I doing wrong here?
Thanks
@sbkl try this
$image = Image::make(request()->file('image'))->resize(400,300)->encode('jpg');
you may have to encode again after resizing the image. you can use jpg or png or any other supported format.
additionally try the following - although it looks like it's being done with __toString()
$path = Storage::disk('s3')->put('/public/items/test.jgp', (string)$image);
Thanks @w1n78 Issue was about reencoding.
I used the stream() method on the image instance to do so instead of encode('jpg').
From the documentation: 'Encodes the current image in given format and given image quality and creates new PSR-7 stream based on image data.'
The following worked for me:
- Laravel 5.4
- Image Intervention 2.4
$image = Image::make($request->file('my_file'))->resize(400, 300);
//Store with stream();
$path = Storage::disk('s3')->put('path/filename.jpg', $image->stream());
Please or to participate in this conversation.