Image source not readable (Upload Job Exception)

Published 6 months ago by splendidkeen

I am trying to handle uploads this way:

First upload the requested file locally, then trigger a UploadLogo Job to push the file to S3 and delete the local pathed-file.

I am always getting this exception:

Intervention\Image\Exception\NotReadableException: Image source not readable 
...

This is my setup:

UploadLogo.php (Job)

public $partner;
public $filename;
    

public function __construct($partner, $filename)
{
        $this->partner = $partner;
        $this->filename = $filename;
}

public function handle()
{
        $path = public_path() . '/uploads/partners/logos/' . $this->filename;
        $filename = $this->filename;

        if (Storage::disk('s3')->put('/uploads/partners/logos/'. $filename, fopen($path, 'r+'))) {
            File::delete($path);
        }
 
        $partner->logo_filename = $filename;
        $partner->save();
}

UploadController.php

public function uploadLogo(Request $request, Partner $partner){

//Validation...

if($request->hasFile('logo')){
    if ($request->file('logo')->isValid()) {
        $partner = Auth::user();

        $image = $request->file('logo');

        $filename = time() . '.' . $image->getClientOriginalExtension();
        $location = public_path('uploads/partners/logos/'. $filename);
        Image::make($image)->resize(300,300)->save($location);

        $partner->logo_filename = $filename;
        $partner->save();
                           
        $this->dispatch(new UploadLogo($partner, $filename));
    }

//Redirect with Info

}
}
rin4ik
rin4ik
6 months ago (266,190 XP)

@splendidkeen did you include this to your form ?

enctype="multipart/form-data"

splendidkeen

Hey and yes @rin4ik

rin4ik
rin4ik
6 months ago (266,190 XP)

@splendidkeen with this?

Image::make($image)->encode('png')->fit(300,300)->save($location);
splendidkeen

No, this won't work either. Same with uploading the file to storage_path...

rin4ik
rin4ik
6 months ago (266,190 XP)

please change this line and try

     $location = public_path('uploads/partners/logos/image.png');
splendidkeen

Still not readable.

splendidkeen

Also tried:

$partner->logo_filename = '/uploads/partners/logos/' . $filename;
rin4ik
rin4ik
6 months ago (266,190 XP)
Image::make($location)->resize(300,300)->save();

splendidkeen

This gives me Image source not readable as an Error page + failed Job.

rin4ik
rin4ik
6 months ago (266,190 XP)

if($request->hasFile('logo')){
    if ($request->file('logo')->isValid()) {
        $partner = Auth::user();

        $image = $request->file('logo'); 
        $location = public_path('uploads/partners/logos/');
        $request->file('logo')->move(location, $filename = uniqid(true));
        $this->dispatch(new UploadLogo($partner, $filename));
    }

//Redirect with Info
}
}
public function handle()
{
    
 $filename = $this->filename . '.png'
    $path = public_path() . '/uploads/partners/logos/' . $filename;
        Image::make($path)->encode('png')->fit(300,300, function ($c) {
            $c->upsize();
        })->save();
        if (Storage::disk('s3')->put('/uploads/partners/logos/'. $filename, fopen($path, 'r+'))) {
            File::delete($path);
        }
 
        $partner->logo_filename = $filename;
        $partner->save();
}
splendidkeen

Now we are getting: Call to a member function move() on null

So the problem is the location.

$request->file('image')->move($location);
rin4ik
rin4ik
6 months ago (266,190 XP)

sorry

  $request->file('logo')->move(location);
splendidkeen

The Upload Job fails again.

The image will be stored locally as a folder.

rin4ik
rin4ik
6 months ago (266,190 XP)

@splendidkeen please try code above I updated

splendidkeen

The Job now only processes/ attempts once, but still not readable.

Please sign in or create an account to participate in this conversation.