2017-09-25 55 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

但是为什么它有时会起作用。刷新相同的路线几次,我相信你会看到图像 –

相关问题