Laravel 和 Intervention/Image:将照片上传到 AWS S3 存储桶会生成 0 字节文件

Laravel and Intervention/Image: Uploading photos to a AWS S3 bucket results in 0 byte files

我使用 http://image.intervention.io/ 和 Laravel 调整图像大小,然后再将它们存储在 AWS S3 存储桶中。这是适用的代码:

$extension = $image->extension();
$realPath = $image->getRealPath();
$resizedImage = Image::make($realPath) // ->resize(255, 255); // resize or not, make() seems to always return an empty Image
$file_path = "posts/$post->id/images/image-$post->id-num-$pictureCount.$extension/"; 
$path = Storage::disk('s3')->put($file_path, $resizedImage->__toString(), ['visibility' => 'public']);

调试时(设置了 $path 行的断点),我可以看到 $realPath 持有一个类似于 /private/var/folders/23/jl2dytp168g9g9s5j51w2m780000gn/T/php9047Fh 的值 - 去那里我可以看到我的图像我正在尝试 make()/resize()

$resizedImage 对象具有以下字段:

[encoded] => 
[mime] => image/jpeg
[dirname] => /private/var/folders/23/jl2dytp168g9g9s5j51w2m780000gn/T
[basename] => phpTNRdXe
[extension] => 
[filename] => phpTNRdXe

我猜编码后的 属性 应该包含类似 base 64 图像数据的内容?

检查 AWS S3 存储桶中的图像时,它总是作为 0 字节的图像上传。我在这里做错了什么?

干预配置为使用 GD(如果有任何不同)

Laravel File class is a subclass of Symfony File class 又是 \ SplFileInfo

的子类

可以直接在Image::make中传递文件对象。 Image::make gets the realPath \SplFileInfo 个对象。

Image::使returns成为Image and $resizedImage->__toString() returns the value of its encoded field. encoded starts out as an empty string.

的实例

在访问其编码值之前,图像应 encoded

$resizedImage->encode();

然后,

$path = Storage::disk('s3')->put($file_path, $resizedImage->__toString(), ['visibility' => 'public']);