(string) $img->encode('jpg')
should work. Otherwise, make sure that your controller is really receiving the file.
Hi. Im having issues with uploading an image to s3 when using Intervention. Ive gone through almost all the forums and google trying all sorts of things but cannot for the life of me get it sorted.
Any help would be grateful.
If i just do it as a S3 upload without Intervention it all works fine but whichever way i do it using Intervention i get an error. Heres what ive got as a base:
$file = request()->file('job_image');
$img = Image::make($file);
$img->resize(null, 500, function ($constraint) {
$constraint->aspectRatio();
});
$path = Storage::disk('s3')->put('u/' . \Auth::id() .'/j/' .
\Carbon\Carbon::now()->toDateString(), $img, 'public');
// Saves to the database
$jobImage = new JobImage(array(
'user_id' => \Auth::id(),
'img_path' => $path
));
$jobImage->save();
Doing it this way i get:
(1/1) ErrorException
fstat() expects parameter 1 to be resource, object given
Ive seen some posts saying to do the path '$img' as '$img->encode()' but this gives me the same error
and also ive tries (string) $img which gives me an error of: The Response content must be a string or object implementing __toString(), "boolean" given.
Any help or information would be grateful...
Cheers
Just for anyone who has this issue...
This worked as stated in the link provided by @Nash
$file = $request->file('avatar');
$path = $file->hashName('avatars');
// avatars/bf5db5c75904dac712aea27d45320403.jpeg
$image = Image::make($file);
$image->fit(250, 250, function ($constraint) {
$constraint->aspectRatio();
});
Storage::put($path, (string) $image->encode());
If its set in the config to upload to S3 by default it will upload to it. If you add "->disk('s3')" it failed with me.
Please or to participate in this conversation.