Laravel 5.4 Image Intervention 在 S3 上上传 0 字节的图像

Laravel 5.4 Image Intervention uploads images on S3 with 0 Bytes

我已经成功创建了一个 Laravel 5.4 Web 应用程序,该应用程序托管在 Heroku 上。我还设法将图像上传到 AWS S3。然而,图像被上传为空白或空的。我尝试了各种在线资源,但未能找到解决问题的方法。下面我附上了我的 控制器 ,我认为这是导致错误的原因。

    public function updateavatar(Request $request, User $user){

if($request->hasFile('avatar')){

    $avatar = $request->file('avatar');
    $filename = time() . '.' . $avatar->getClientOriginalExtension();
    // $destinationPath = public_path('/uploads/avatars/');

    $imageS3 = Image::make($avatar)->resize(300,300);

    Storage::disk("s3")->put($filename, $imageS3->__toString());
    //$disk->put("img/album/$id/$filename", $image->__toString());

$motcall = $this->carCheck($user);
    $user = Auth::user();
    $user->avatar = $filename;
    $user->save();

}

我的 存储桶 中的问题示例

我已通过将存储行更改为 Storage::disk("s3")->put($filename, file_get_contents($avatar)) 来解决问题;
P.S 它忽略图像裁剪

编码对我有用:

for "s3"

Storage::disk('s3')->put('/downloads/' . $fileName, $interventionImage->encode(), 'public');

for local storage

Storage::disk('public')->put('/downloads/' . $fileName, $interventionImage->encode(), 'public');