2017-01-22 48 views
0

我試圖節省干預圖像編碼到特定的存儲保存文件到存儲干預編碼

$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'); 

後返回一個錯誤:

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

Call to undefined method GuzzleHttp\Psr7\Stream::getRealPath() 

與另一種嘗試

錯誤:

Call to a member function getRealPath() on string 

任何解決方法使用存儲保存文件?

回答

0

問題是Storage::putFileAs()需要一個\Illuminate\Http\File\Illuminate\Http\UploadedFile,這就是爲什麼它試圖打電話給getRealPath()

但是,Storage::put不會,它會很高興地採取PSR-7流。嘗試:

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

@ user947668沒有這充分回答你的問題? – Dominic

0

建築上星的回答是:

您需要的文件或UploadedFile的一個實例。

例如:

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