Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which HTTP status code should be used for a UPLOAD_ERR_PARTIAL?

I'm developing a REST API and I have some file uploads:

PHP can generate an UPLOAD_ERR_PARTIAL error when the file was only partially uploaded, and I'm not sure of which HTTP status code should be used in this case.

This usually happens if the user cancels the upload (see Why might a file only be partially uploaded and file upload errors on php.net )

UPLOAD_ERR_PARTIAL is given when the mime boundary is not found after the file data. A possibly cause for this is that the upload was cancelled by the user (pressed ESC, etc).

like image 452
pconcepcion Avatar asked Aug 14 '13 13:08

pconcepcion


2 Answers

i think the header should be based on error context:

if the file upload is not an allowed type:

  • HTTP_415 = 'Unsupported Media Type'

if the file upload it too big:

  • HTTP_413 = 'Request Entity Too Large'

if the server has a problem w/ the upload:

  • HTTP_500 = 'Internal Server Error'

if the upload times out:

  • HTTP_504 = 'Gateway Timeout'

but in general, i would say that 500 is pretty standard.

like image 111
xero Avatar answered Sep 27 '22 17:09

xero


You should use 409 status code for this case.

According to http://www.ietf.org/rfc/rfc2616.txt:

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where
it is expected that the user might be able to resolve the conflict
and resubmit the request. The response body SHOULD include enough
information for the user to recognize the source of the conflict.
Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be
possible and is not required.

like image 27
Michael Sivolobov Avatar answered Sep 27 '22 18:09

Michael Sivolobov