layui.upload reports an error when uploading pictures, "The request upload interface is abnormal" and the interface reports a 404 problem
When debugging layui.upload to upload pictures, an error "An exception occurred in the request upload interface" is reported:
And the interface return is 404, the return interface is lost.
Process of review processing:
After spending some incidents, I did the following problem screening and processing. First of all, we must confirm whether the interface is connected. Find a smaller picture and try it, about 1kb. If the interface is not working, then just adjust the interface. I found here that the files below 5kb can be uploaded, and the ones above 150k will cause problems and errors. Then there is no problem with the interface! I use postman to debug separately here.
Guess it may be php.ini, nginx upload limit problem, check php.ini:
upload_max_filesize = 50m ;
There is no problem setting the upper limit of upload size, within the range; check nginx.conf:
client_max_body_size 50m;
There is no problem with the maximum limit, and it is set large enough.
Then it means that nginx encountered a problem and interrupted, so it returned a 404, so check the error log (nginx log) generated after the file was uploaded and the interface was asked:
Find the crux of the problem, open() "/usr/local/var/run/nginx/client_body_temp/0000000001" failed (13: Permission denied), access permission problem.
Analyze the reasons:
The client POSTs a relatively large file whose length exceeds the size of the nginx buffer. Part or all of this file needs to be temporarily stored in a temporary file in the client_body_temp directory. Therefore, there is no problem with submitting 5Kb of data. If it exceeds a certain size, it needs to be temporarily stored in the buffer area. So here you need to pay attention to such small pits!
Processing method:
To solve this /usr/local/var/run/nginx/client_body_temp directory read and write permissions will do, as follows (Mac console):
Check permissions first
ls -l
Promote users
Increase read and write permissions
chmod -R 755 client_body_temp/
There is no problem in operating the interface or uploading pictures.