我必须从我的Angular前端获取存储在服务器中的私人图像,但我不知道如何获取这些图像,而不将其保存在Laravel/Lumen包含的/public文件夹中。
我们的想法是发送一个包含用户信息的GET HTTP请求,此路由应返回图像。有没有办法做到这一点,还有其他的可能性吗?
提前谢谢。
发布于 2019-10-15 22:05:37
// Storing the incoming file on the local storage driver (not public)
$filePath = request()->file_name->store('some_folder_name');
// Returning the image
return response()->file(Storage::path($filePath));<!-- displaying the image -->
<img src="{{ route('some_route_to_return_the_file_repsonse') }}" />希望这能有所帮助。
编辑:我刚刚找到了一个更广泛的答案here
发布于 2019-10-15 21:57:07
我希望我的回答能对你有所帮助。在Laravel中,有一个公共磁盘。公共磁盘用于存储将可公开访问的文件。要建立从/public到storage/app/public的连接,您必须运行:
php artisan storage:link
当您将镜像保存到公共磁盘时,您将看到如下内容:
Storage::disk('public')->put('file.txt', 'Contents');
从公有磁盘获取公有镜像
Storage::disk('public')->get('file.txt');
您还可以构建自己的路径,因此在put/get上,您可以拥有'custom_path/file.text'等等。
您可以从here获取的完整信息。我希望这能解决你的问题。
https://stackoverflow.com/questions/58395728
复制相似问题