gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:20:03 24 4
gpt4 key购买 nike

我正在尝试使用 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;

我没有得到错误

最佳答案

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

关于php - Laravel 队列错误 'Illuminate\Http\UploadedFile' 的序列化是不允许的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40552818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com