We are developing an application that allows a user to upload file on rest end point.
Could someone please guide if it is correct to send 400 error code for the failure of following validation scenario:
1) The Length of file name exceeds permissible limit.
2) File name contains special characters
3) Uploaded file was empty
4) The System failed to read the uploaded file from disk.
Regards, Tarun
I think the 400
is not an appropriate because syntax of the request is correct in this case. The 422 Unprocessable Entity
is better in this case.
Illegal characters mean the syntax is broken. So 400 Bad Request
is a proper response in this case. Someone may claim that a definition of illegal characters is needed so the server may authoritatively send 400
.
I think it is not an error because an empty file is a legal file.
Does the system mean the server? Then the server should return a 5xx
response because it is not a client failure. In case of general read error the server should return 500
.
EDIT:
Uploaded file was empty.
When application semantic forbids an empty file the 400
or 422
appropriate. More details about them is at 400 vs 422 response to POST of data