Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kekekiw123's avatar

Serialization of 'Illuminate\Http\UploadedFile' is not allowed On queue

I am trying to fire a queue(bean) to upload files but I get this errro: Serialization of 'Illuminate\Http\UploadedFile' is not allowed

My queue looks like this:

protected $file;
    protected $Id;

public function __construct($file,$Id)
    {
        $this->file = $file
        $this->Id = $Id;
    }
public function handle()
    {
        $qFile = $this->file;
        $qId = $this->Id;

        $s3 = Storage::disk('s3');
        $extension = $qFile->guessExtension();
        $filename = uniqid().'.'.$extension;

      //Create and resize images
      $image = Image::make($qFile)->resize(null, 600, function ($constraint) {
          $constraint->aspectRatio();
      });
        $image->encode($extension);

        $imageLarge = Image::make($qFile)->resize(null, 800, function ($constraint) {
          $constraint->aspectRatio();
      });
        $imageLarge->encode($extension);

      // upload image to S3
      $s3->put("images/{$qId}/main/".$filename, (string) $image, 'public');
        $s3->put("images/{$qId}/large/".$filename, (string) $imageLarge, 'public');

      // make image entry to DB
      File::create([
          'a_f_id' => $qId,
          'file_name' => $filename,
      ]);
    }

But if I remove

protected $file;
    protected $Id;

I dont get the error

0 likes
6 replies
martinbean's avatar
Level 80

@kiwo123 You can’t pass an uploaded file instance to a job. You need to write it to disk somewhere, and then retrieve it when handling the job.

11 likes
kekekiw123's avatar

@martinbean so how should I handle files uploads the best way? First store it then make a queue that uploads it and deletes the old image from disk?

kekekiw123's avatar

@martinbean now I am saving images direct by

@jekinney I tried to do what you describe here: https://laracasts.com/discuss/channels/general-discussion/resize-image-saved-in-storagedisk-using-intervention/replies/188151

$extension = $file->guessExtension();
      $filename = 'thumnail_'.$id.'.'.$extension;
      if ($file) {
          $s3 = Storage::disk('local')->put($filename, $file);
      }
      $this->dispatch(new UploadImagesThumb($filename, $id));

But then my worker gives me the error: Intervention\Image\Exception\NotReadableException: Image source not readable in /home/forge/default/vendor/intervention/image/src/Interventio$ Stack trace: #0 /home/forge/default/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(64): Intervention\Image\AbstractDecoder->init('/tmp/phpcpMqyA') #1 /home/forge/default/vendor/intervention/image/src/Intervention/Image/ImageManager.php(50): Intervention\Image\AbstractDriver->init('/tmp/phpcpMqyA') #2 /home/forge/default/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(217): Intervention\Image\ImageManager->make('/tmp/phpcpMqyA') #3 /home/forge/default/app/Jobs/UploadImagesThumb.php(35): Illuminate\Support\Facades\Facade::__callStatic('make', Array)

My queue looks like this:

$image = Storage::disk('local')->get($this->filename);

        $s3 = Storage::disk('s3');
        $imageThumb = Image::make($image)->fit(320);
        //Always set thumbnail as jpg
        $imageThumb->encode('jpg');
        $s3->put("images/{$this->Id}/thumb/thumbnail.jpg", (string) $imageThumb, 'public');

Please or to participate in this conversation.