Lv007
Lv007

Reputation: 577

Laravel 5.4 Image Intervention uploads images on S3 with 0 Bytes

I have successfully created a Laravel 5.4 web application which is hosted on Heroku. I have also have managed that images gets uploaded on AWS S3. However the images gets uploaded as blank or empty. I have tried various online sources and have not been able to find a solution to my problem. Below I have attached my controller, which I believe is causing the error.

    public function updateavatar(Request $request, User $user){

if($request->hasFile('avatar')){

    $avatar = $request->file('avatar');
    $filename = time() . '.' . $avatar->getClientOriginalExtension();
    // $destinationPath = public_path('/uploads/avatars/');

    $imageS3 = Image::make($avatar)->resize(300,300);

    Storage::disk("s3")->put($filename, $imageS3->__toString());
    //$disk->put("img/album/$id/$filename", $image->__toString());

$motcall = $this->carCheck($user);
    $user = Auth::user();
    $user->avatar = $filename;
    $user->save();

}

An example how the issue looks like in my bucket enter image description here

Upvotes: 3

Views: 1471

Answers (2)

Bilal
Bilal

Reputation: 125

encode worked for me:

for "s3"

Storage::disk('s3')->put('/downloads/' . $fileName, $interventionImage->encode(), 'public');

for local storage

Storage::disk('public')->put('/downloads/' . $fileName, $interventionImage->encode(), 'public');

Upvotes: 0

Lv007
Lv007

Reputation: 577

I have managed to resolve the issue by changign the storage line to Storage::disk("s3")->put($filename, file_get_contents($avatar));
P.S it ignores the image crop

Upvotes: 1

Related Questions