Laravel 干预编码后将文件保存到存储器

Laravel 干预编码后将文件保存到存储器,laravel,laravel-5.3,intervention,Laravel,Laravel 5.3,Intervention,我正试图将干预编码的图像保存到特定的存储器中 $converted_image = Image::make($req->file('image_file')); $converted_image->resize(300, null, function ($constraint) { $constraint->aspectRatio(); }); $file=$converted_image->encode('png'); $path = Storage::putF

我正试图将干预编码的图像保存到特定的存储器中

$converted_image = Image::make($req->file('image_file'));
$converted_image->resize(300, null, function ($constraint) {
    $constraint->aspectRatio();
});
$file=$converted_image->encode('png');
$path = Storage::putFileAs('images', $file->stream(), 'test.png');
返回一个错误:

Call to undefined method GuzzleHttp\Psr7\Stream::getRealPath()
另一次尝试是:

$path = Storage::putFileAs('images', $file->stream()->__toString(), 'test.png');
错误:

Call to a member function getRealPath() on string

使用存储来保存文件的任何解决方法?

问题是
存储::putFileAs()
需要
\light\Http\file
\light\Http\UploadedFile
,这就是它试图对其调用
getRealPath()
的原因

但是,
Storage::put
没有,它将很乐意接受一个PSR-7流。尝试:

Storage::put('images/test.png', $file->stream());

基于多米尼克的回答:

您需要文件或上载文件的实例

例如:

Storage::putFileAs('images', new Illuminate\Http\File($file->stream()->__toString()), 'test.png');

@user947668这是否充分回答了您的问题?为什么投反对票?这是一个有效的解决方案(至少在当时是)