我正在尝试使用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,
]);
}
但如果我删除:
protected $ file; protected $ Id;
我没有收到错误
答案 0 :(得分:1)
您无法将上传的文件实例传递给作业。您需要将其写入磁盘某处,然后在处理作业时检索它。