jeudi 12 mars 2020

Laravel and Intervention/Image: Uploading photos to a AWS S3 bucket results in 0 byte files

I'm using http://image.intervention.io/ with Laravel to resize images before storing them in an AWS S3 bucket. Here is the applicable code:

$extension = $image->extension();
$realPath = $image->getRealPath();
$resizedImage = Image::make($realPath) // ->resize(255, 255); // resize or not, make() seems to always return an empty Image
$file_path = "posts/$post->id/images/image-$post->id-num-$pictureCount.$extension/";
$path = Storage::disk('s3')->put($file_path, $resizedImage->__toString(), ['visibility' => 'public']);

When debugging (breakpoint on the line $path is set) this I can see that $realPath holds a value like /private/var/folders/23/jl2dytp168g9g9s5j51w2m780000gn/T/php9047Fh - and going there I can see the image that I'm trying to make()/resize().

The $resizedImage object has the following fields:

[encoded] => 
[mime] => image/jpeg
[dirname] => /private/var/folders/23/jl2dytp168g9g9s5j51w2m780000gn/T
[basename] => phpTNRdXe
[extension] => 
[filename] => phpTNRdXe

I'm guessing that the encoded property should hold something like the base 64 image data?

When checking the image in AWS S3 bucket, it is always getting uploaded as a image with 0 bytes. What am I doing wrong here?

Intervention is configured to use GD.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire