从 Laravel 存储中检索视频 [英] Retrieve video from Laravel Storage
问题描述
目前我正在通过 create()
函数中的以下代码将视频发送到 Laravel 中的存储文件夹:
Currently I am sending a video to the storage folder in Laravel through the following piece of code inside a create()
function:
if ($request->hasFile('video_url')) {
$video = $request->file('video_url');
$folder = make_url($validated['title']);
$video_name = time().'-vid.'. $video->getClientOriginalExtension();
Storage::disk('local')->put('/uploads/' . $folder . '/', $video);
$validated['video_url'] = $folder . '/' . $video->hashName();
}
它创建视频,将其发送到正确的文件夹,并将视频的 URL 发送到数据库,以便我始终可以检索正确的链接.这一切正常.
It creates the video, send it to the proper folder and it sends the URL of the video to the database so that i can always retrieve the correct link. This all works fine.
我不知道如何从存储中检索视频以进行播放.
I have no idea how to retrieve the video for playback from storage though.
我尝试在视频标签中手动检索链接,但是,当然,存储文件夹不是公开的,所以这不起作用.
I have tried to retrieve the link manually inside the video tags but, of course, the storage folder is not public so this did not work.
{{$vid = Storage::disk('local')->get('/uploads/' . $e_course_chapter->video_url)}}
{{ var_dump($vid) }}
<video controls>
<source src="{{ Storage::disk('local')->get('/uploads/' . $e_course_chapter->video_url) }}" type="video/mp4">
Your browser does not support the video tag.
</video>
var_dump
给了我这个:
/home/vagrant/code/storage/framework/views/777c4fe762b993d5be04ad6550ee11200bd4869d.php:49:string '���ftypmp42����mp42isomavc1����free�������������������������������������������������������������������������������������������������������������������������������mdat�� ���E���H��,� �#��x264 - core 79 - H.264/MPEG-4 AVC codec - Copyleft 2003-2009 - http://www.videolan.org/x264.html - options: cabac=0 ref=2 deblock=1:0:0 analyse=0x1:0x111 me=umh subme=6 psy=1 psy_rd=1.0:0.0 mixed_ref=1 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 chroma_qp_offset=-2 threads=6 nr=0 decimate=1 mbaff=0'... (length=383631)
推荐答案
您可以创建一个路径,您可以从中获取视频并在视图中使用该路径.
You can create a route from which you can get the video and use that route in view.
在控制器中:
function getVideo() {
$video = Storage::disk('local')->get("uploadpath_here");
$response = Response::make($video, 200);
$response->header('Content-Type', 'video/mp4');
return $response;
}
在视图中:
use <source src="{{ route('/get-video') }} ... >
途中:
Route::get('/get-video', Controller@getVideo);
依次调用控制器函数.
这篇关于从 Laravel 存储中检索视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!