我正在尝试使用 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;
我没有得到错误
| 归档时间: |
|
| 查看次数: |
9061 次 |
| 最近记录: |