Laravel 队列错误 'Illuminate\Http\UploadedFile' 的序列化是不允许的

use*_*197 5 php laravel

我正在尝试使用 laravel 中的队列(bean)上传文件,但出现此错误:不允许序列化 'Illuminate\Http\UploadedFile'

我的代码是:

    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,
      ]);
    }
Run Code Online (Sandbox Code Playgroud)

但如果我删除:

受保护的 $file; 受保护的 $Id;

我没有得到错误

Ita*_*cia 8

您不能将上传的文件实例传递给作业。您需要将其写入磁盘某处,然后在处理作业时检索它。

  • 你能给我们举个例子吗? (5认同)