GaryC's avatar
Level 6

Queued Job Won't Store Image

I'm trying to store uploaded images to s3. The storage and retrieval works fine, however, when I try to store using a queued job, I receive the following error:

[ErrorException]                                                                                            
  file_get_contents(users/avatars/avatar_104_IMG_0518.jpg): failed to open stream: No such file or directory

I am using beanstalkd as my queue driver. Here is the handle method on my job:

public function handle()
    {
        // Store the file
        Storage::put(
            'avatars/' . $this->user->id,
            file_get_contents($this->avatar),
            'public'
        );

        // Set the new avatar
        $this->user->changeAvatar();

        // Delete the image file
        unlink($this->avatar);
    }

So for some reason file_get_contents() is not working from within the Job.

Anyone have any ideas?

Thanks, Gary

0 likes
2 replies
d3xt3r's avatar

Its says what it says No such file or directory. What is $this->avatar ?

GaryC's avatar
Level 6

That is the original location where the image is saved when it is uploaded. I run it through Intervention to edit it first.

You're right though; no such file. I was still using the path to the image defined in my Controller and I needed to use the full path inside the Job.

Please or to participate in this conversation.