简体   繁体   中英

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).

如果用户的上传失败是因为他们上传的内容有问题,请说: 400 Bad Request

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.

您不必发送任何状态代码,因为客户端已经断开连接。

I would go with either 422 (request unable to be followed due to semantic errors) or 449 (request should be retried after performing action).

Take a look at httpstatuses.com .

UPLOAD_ERR_PARTIAL is given when the mime boundary is not found after the file data .

411 Length Required

The request did not specify the length of its content, which is required by the requested resource

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.

I would use

408 Request timeout. As it indicates that the request was only sent partially (which is not supported in this case)

400 Bad Request looks like an other option.

You can also create your own using a non reserved number.

But where do you send the response if the request is cancelled?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM