Laravel队列错误不允许序列化'Illuminate \ Http \ UploadedFile' [英] Laravel queue error Serialization of 'Illuminate\Http\UploadedFile' is not allowed
本文介绍了Laravel队列错误不允许序列化'Illuminate \ Http \ UploadedFile'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用laravel中的队列(bean)上传文件,但出现此错误:不允许对'Illuminate \ Http \ UploadedFile'进行序列化
I am trying to upload a file using a queue(bean) in laravel but I get this error: Serialization of 'Illuminate\Http\UploadedFile' is not allowed
我的代码是:
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,
]);
}
但是如果我删除:
受保护的$ file;受保护的$ Id;
protected $file; protected $Id;
我没有收到错误
推荐答案
您无法将上传的文件实例传递给作业.您需要将其写入磁盘中的某个位置,然后在处理作业时将其检索.
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.
这篇关于Laravel队列错误不允许序列化'Illuminate \ Http \ UploadedFile'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文