Error Message
The server returned a “413 Content Too Large”.
Other Information
I have a form to upload videos, the videos I upload are directly saved to YouTube without saving them to the database. Only the title, description, and YouTube ID attributes are saved to the database, but why do I get the error message “The server returned “413 Content Too Large”.”
how to fix it?
public function store(Request $request) {
$apiKey = env('GOOGLE_API_KEY');
$user = Auth::user();
$googleToken = $user->google_token;
$client = new Client();
$client->setAuthConfig(base_path('google-oauth-client.json'));
$client->setDeveloperKey($apiKey);
$client->setRedirectUri(env('GOOGLE_REDIRECT_URI'));
$client->addScope(YouTube::YOUTUBE_UPLOAD, Youtube::YOUTUBE);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setAccessToken([
'access_token' => $googleToken,
'expires_in' => 7200,
]);
$request->validate(
[
'title' => 'required',
'description' => 'required',
'video_url' => 'file|mimetypes:video/mp4,video/avi,video/mkv|max:150000', // Maks 150MB
],
[
'title.required'=> 'Title is required',
'description.required'=> 'description is required',
'video_url.mimetypes' => 'Video formats only MP4, AVI, or MKV',
'video_url.max' => 'Maximum video size is 150MB',
]
$service = new Youtube($client);
$snippet = new VideoSnippet();
$status = new VideoStatus();
$video_youtube = new Video();
$snippet->setTitle($request->title);
$snippet->setDescription(Str::of($request->description)->stripTags());
$status->setPrivacyStatus('unlisted');
$video_youtube->setSnippet($snippet);
$video_youtube->setStatus($status);
$video_file = $request->file('video_url');
$video_path = file_get_contents($video_file->getPathname());
$video_mime = $video_file->getMimeType();
$insertRequest = $service->videos->insert('snippet,status', $video_youtube, ['data' => $video_path, 'mimeType' => $video_mime]);
$dataStore = [
'title'=> $request->title,
'slug'=> $this->generateSlug($request->title),
'description'=> $request->descr,
'youtube_video_id' => isset($insertRequest->id) ? $insertRequest->getId() : null
'user_id' => $user->id,
];
Post::create($dataStore);
return redirect()->route('admin.blogs.index')->with('success', 'successful adding data');
}