【Laravel】413 (payload too large) error handling
Thank you for your continued support.
This article contains advertisements that help fund our operations.
When uploading files such as videos or images,
Here is an article on how to handle the 413 (payload too large) error.
1. Why does it happen
Whether it's a local server or a production server, there are server settings.
In those server settings,
There are specified limits for "maximum file size that can be sent via POST" and "maximum file size that can be saved".
If you don't set this, it's because if you receive a file of 1 trillion gigabytes, it's over.
Validation on the front end → Validation on the server side → Validation in server settings
Let's definitely escape from the 1 trillion gigabyte files.
2. How to view server settings
Anywhere is fine, but in a Blade file (on the page where you are currently fighting bugs),
<?php phpinfo() ?>
Write this code and try pressing update...
The server information of PHP will be displayed like this. It's very long. Among that,
upload_max_filesize 30M 30M
post_max_size 30M 30M
There should be specifications like this. The top is the upload limit, and the bottom seems to be the POST limit.
I handle videos, so I give a slightly wider margin, setting it to 30M.
3. Editing method
You can change these numbers by editing the file that contains server settings.
Where is it... it is written in phpinfo().
Loaded Configuration File /usr/local/etc/php/7.4/php.ini
For example, like this!
This varies depending on the local situation you are running.
You can also search with Finder, but since there are only two places to edit, let's use Vim in the terminal to make the modification.
Vim is like a Notepad that you operate in the terminal, and you can easily open a file if you know the file path.
In the terminal command
Simply input the path after Vim. This time,
vim /usr/local/etc/php/7.4/php.ini
and you're good to go.
Then a lot of text appears. It can be intimidating at first.
Vim has "Viewing mode?" and "Editing mode?" (I don't know the formal names),
To switch to editing mode, press a key on the keyboard (I press a myself), and you can start editing.
It has a unique operation feel, so be careful not to accidentally delete anything.
To switch from editing mode to viewing mode, press ESC.
While in viewing mode,
/
Just the slash
type this.
You should see a / at the bottom of the terminal.
If it doesn't appear, you might be in editing mode, so be careful.
Even if it's not a half-width character, it probably won't work.
You can search with /search keyword.
So,
/upload_max_filesize
type this to search.
After searching, go to editing mode to change the number.
Press ESC, switch to viewing mode, search for post_max_size in the same way and make changes.
While in viewing mode,
:wq
This will save the changes and quit, ending the editing process.
Then go back to phpinfo().
If the numbers you checked earlier have changed, it's a success!
Summary
That's all. Did it work out for you?
For feedback or complaints, please contact me via Twitter DM.
I plan to continue writing Laravel articles in the future, so please follow me~.