2017-09-25 24 views
0

laravel route有時會返回圖像,並且在其他時間返回錯誤頁面。什麼可能會出錯。這個Laravel路線每次都會返回不同的答案 - 我在哪裏尋找錯誤?

這條路線只返回類似這樣的形象:

public function image(Request $request) { 
    return response()->file(storage_path('app/'.$request->input('path'))); 
} 

我存儲使用此代碼的圖像:

$path = $request->p->store('public/images'); 
    Storage::setVisibility($path, 'public'); 

我不知道發生了什麼錯誤。當請求路由時,我會看到這個日誌。

NOTICE: PHP message: [2017-09-25 18:33:25] production.ERROR: Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException: The file "/app/storage/app/public/images/YxNllK0iVKAxxUSCEhFHLo5sGZiXg5NNbGDbOVSL.jpeg" does not exist in /app/vendor/symfony/http-foundation/File/File.php:37

,路線在它的盛開:

https://resonant-tower-177816.appspot.com/showimage?path=public/images/YxNllK0iVKAxxUSCEhFHLo5sGZiXg5NNbGDbOVSL.jpeg 

這絕對不是因爲沒有圖像出現。我可以向你保證這條路線在某些時候有效。

出了什麼問題?

我在Google App Engine上使用Laravel 5.4。

+0

我很抱歉。這是一個愚蠢的問題。我在兩個實例上運行Laravel。顯然,Google雲應用引擎Flex環境自動擴展爲2個實例 –

回答

0

錯誤路徑 「/應用/存儲/程序/公/圖像」 正確的路徑是像 「/存儲/程序/公/圖片」 所以,你應該改變

public function image(Request $request) { 
return response()->file(storage_path('app/'.$request->input('path'))); 

} 到

public function image(Request $request) { 
return response()->file(storage_path($request->input('path'))); 

}

+0

但是爲什麼它有時會起作用。刷新相同的路線幾次,我相信你會看到圖像 –

相關問題