YES or NO: Can a server send an HTTP response, while still uploading the file from the correlative HTTP request?

梦想与她 提交于 2020-01-21 15:25:03

问题


If a website user submits an HTML form with: (1) a post method; (2) a multipart/form-data enctype; and, (3) a large attached file, can the server upload a posted file, and send a server generated HTTP response before the file upload is completed, without using AJAX?

That's pretty dense. So, I wrote an example to illustrate what I mean. Let's say there is an image upload form with a caption field.

  <form action="upload-with-caption/" method="post" enctype="multipart/form-data">
    <input type="hidden" id="hiddenInfo" name="hiddenInfo" />
    File:     <input type="file" name="imgFile" id="imgFile" /><br />
    Caption:  <input type="text" name="caption" id="caption" />
        <input type="submit" />
  </form>

I want to store the caption in a database table with the the definition:

[files_table]

  • file_id [uniqueidentifier]
  • file_caption [varchar(500)]
  • file_status [int]

Then I want to upload the file to /root/{unique-id}/filename.ext.

file_status is mapped to a C# enum with the following definition:

enum  FileUploadStatus{
    Error = 0,
    Uploading = 1,
    Uploaded = 2
}

When the form submits, if the file is too large to process in 1 second, I want to send the webpage back a response that says it is currently uploading.

Can I do this with a single synchronous HTTP post?

Note: I will obviously want to check for the status updates later using AJAX, but that is not what this question is asking. I am specifically asking if the file can continue to upload after the response is sent.


回答1:


HTTP is a synchronous protocol.
You cannot send a response until you receive the entire request.



来源:https://stackoverflow.com/questions/4796470/yes-or-no-can-a-server-send-an-http-response-while-still-uploading-the-file-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!