【发布时间】:2021-12-08 14:34:11
【问题描述】:
我正在使用Spatie/Laravel-Medialibrary 处理我的产品模型的文件附件。我想将所有产品图片上传到 Amazon S3,然后将每张图片自动转换为不同的尺寸(即“拇指”、“小”、“中”、“大”),如 documented here。
使用本地文件系统时一切正常。该包创建转换,我可以使用我的应用程序访问它们。当我尝试将包的设置更改为使用 Amazon 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');
}
正如我上面提到的,如果我使用本地文件系统,一切都会很好,但是一旦我将其更改为使用 Amazon S3,就不会创建文件转换。原始文件已成功上传到亚马逊,但没有转换。有什么建议吗?
【问题讨论】:
标签: php amazon-s3 laravel-5.2