我正在使用Spatie/Laravel-Medialibrary处理我的产品模型的文件附件。我想有所有的产品图像上传到亚马逊S3,然后有每个图像自动转换为不同的大小(即“拇指”,“小”,“中”,“大”),如documented here。
在使用本地文件系统时,一切都运行得很好。这个包创建了转换,我可以通过我的应用程序访问它们。当我尝试更改软件包的设置以使用亚马逊S3而不是本地文件存储时,问题就出现了。
因此,在我的ImageController.php中,我有以下几行:
$product->addMedia(public_path() . '/temp/products/'.$product->id)->toCollection('images', 's3');config/filesystems.php中的S3配置
's3' => [
'driver' => 's3',
'key' => env('AMAZON_S3_ID'),
'secret' => env('AMAZON_S3_KEY'),
'region' => env('AMAZON_S3_REGION'),
'bucket' => env('AMAZON_S3_BUCKET'),
'visibility' => 'public'
],和我的Product.php类中的转换设置:
public function registerMediaConversions()
{
$this->addMediaConversion('thumb')
->setManipulations(['w' => 160, 'h' => 120])
->performOnCollections('images');
$this->addMediaConversion('small')
->setManipulations(['w' => 280, 'h' => 210])
->performOnCollections('images');
$this->addMediaConversion('medium')
->setManipulations(['w' => 400, 'h' => 300])
->performOnCollections('images');
$this->addMediaConversion('large')
->setManipulations(['w' => 640, 'h' => 480])
->performOnCollections('images');
}正如我上面提到的,如果我使用本地文件系统,一切都很好,但一旦我将其更改为使用亚马逊S3,就不会创建文件转换。原始文件已成功上载到Amazon,但转换不存在。有什么建议吗?
发布于 2016-12-01 10:29:45
我不知道为什么,但是当添加nonQueued()时,它对我来说是有效的。
public function registerMediaConversions()
{
$this->addMediaConversion('thumb')
->setManipulations(['w' => 160, 'h' => 120])
->performOnCollections('images')
->nonQueued();
$this->addMediaConversion('small')
->setManipulations(['w' => 280, 'h' => 210])
->performOnCollections('images')
->nonQueued();
$this->addMediaConversion('medium')
->setManipulations(['w' => 400, 'h' => 300])
->performOnCollections('images')
->nonQueued();
$this->addMediaConversion('large')
->setManipulations(['w' => 640, 'h' => 480])
->performOnCollections('images')
->nonQueued();
}发布于 2019-02-10 03:41:56
因为转换是作为“队列”工作的,所以您的服务器不会设置队列。
阅读更多Laravel文档https://laravel.com/docs/5.7/queues
发布于 2021-05-28 12:38:26
您可能尚未使用php artisan queue:work或php artisan queue:listen启动队列工作程序。还要确认您已经在.env文件中正确设置了队列配置(如QUEUE_CONNECTION)。
https://stackoverflow.com/questions/39433365
复制相似问题