我一直在開發一項服務,用戶只能訪問內容,并且只有在他們為內容付費的情況下才能訪問內容。所以我正在將內容上傳到存儲目錄,并且為了訪問內容,我已經創建了這樣的路由。Route::any('storage/course/videos/{video_id}',['uses'=>'StorageController@video','middleware'=>'auth']);然后在存儲控制器中,我正在獲取文件并將其作為響應返回,如下所示...public function video($video_id){ //Some logic for subscription check goes here $path = storage_path('app/public/course/videos/'.$video_id); // return $path; if (!File::exists($path)) { abort(404); } $file = File::get($path); $type = File::mimeType($path); $response = Response::make($file, 200); $response->header("Content-Type", $type); // $response->header("Accept-Ranges", 'bytes'); //$response->header("Content-Length", 51265590); // $response->header("Content-Disposition" ,"attachment"); //Triggers Download return $response; }此技巧對圖像按預期工作,但不適用于 視頻 。即使視頻下載正在工作,但瀏覽器每次都無法播放視頻。最初,我認為可能會缺少一些標題,但我嘗試了一些標題,但它不起作用。那么,任何人我做錯了什么,或者是否有可能這樣做,或者任何其他技術來實現這一點提前致謝?。?
1 回答

交互式愛情
TA貢獻1712條經驗 獲得超3個贊
在使用我從此處獲得的其他VideoStream類后,它起作用 https://gist.github.com/vluzrmos/d5682ad426525196d069
public function video($video_id){
$path = storage_path('app/public/course/videos/'.$video_id);
if (!File::exists($path)) {
abort(404);
}
$stream = new \App\Http\VideoStream($path);
return response()->stream(function() use ($stream) {
$stream->start();
});
}
- 1 回答
- 0 關注
- 114 瀏覽
添加回答
舉報
0/150
提交
取消