file upload is often required in the application system, the general practice is to use the HTML <form> and <input type= "file", or use third-party files to upload components, such as SWFUpload and uploadify. We all know that if you submit data to the server, typically using a POST request, the request data is placed in the request body in key1=value1&key2=value2 form. Such a message, the server is very easy to parse. If it is uploading files, through the HttpWatch capture tool, we can find: the contents of the file is also placed in the POST request body.
We know that when you submit a form, you can upload the file and submit the parameter values at the same time. This raises the question: the request parameter value and the file content are in the POST request body, the server must be able to identify the message, which is the parameter value, which is the file content? How does the HTTP protocol solve this problem? You can view the rfc1867 document:form-based file Upload in HTML. There are 2 blog posts below.
Http://www.cnblogs.com/chy710/archive/2010/02/22/1671007.html
http://blog.csdn.net/xiaojianpitt/article/details/6856536
the implementation details are well explained. If the details of the message, we can use httpclient and other open source components, self-build request messages, to achieve file upload. We know that the HTTP request is stateless and the connection hold time is not too long. So how to achieve efficient and robust file upload, need to consider a lot of details, need to understand the HTTP protocol some of the head such as contenttype,keep alive mechanism.
After implementing the basic upload function, it is generally necessary to consider how to upload large files. How do I implement a breakpoint upload? How do I implement asynchronous uploads? Upload Multiple files together? Wait a minute.