I am creating a youtube video downlaoding project. I have fetched the video detail with Youtube API. But on trying to download the video. A webpage downloads instead of video.
I am using Laravel for this project. This is my controller code below for downloading the video.
public function DownloadVideo($videoId) { $videoUrl = "https://www.youtube.com/watch?v={$videoId}"; $filename = "video_{$videoId}.mp4"; if (Storage::exists($filename)) { $filePath = Storage::path($filename); return response()->download($filePath, $filename, ['Content-Type' => 'video/mp4', ], 'inline'); } }Tried to log the file content and filepath
if (Storage::exists($filename)) { $filePath = Storage::path($filename); Log::info("File path: $filePath"); Log::info("File content: " . file_get_contents($filePath)); return response()->download($filePath, $filename, [], 'inline'); }in file content i got web page code.