In fact, the principle of resumable upload is very simple, that is, the HTTP request is different from the general download.
For example, when a browser requests a file on the server, the request is as follows:
Assume that the server domain name is wwww.scu.edu.cn, and the file name is down.zip.
GET/down.zip HTTP/1.1
Accept: image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, application/vnd. MS-
Excel, application/MSWord, application/vnd. MS-PowerPoint ,*/*
Accept-language: ZH-CN
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Connection: keep-alive
After receiving the request, the server searches for the requested file, extracts the file information, and then returns it to the browser. The returned information is as follows:
200
Content-Length = 106786028
Accept-ranges = bytes
Date = Mon, 30 Apr 2001 12:56:11 GMT
Etag = W/"02ca57e173c11: 95b"
Content-Type = application/octet-stream
Server = Microsoft-Microsoft IIS/5.0
Last-modified = Mon, 30 Apr 2001 12:56:11 GMT
The so-called resumable upload means that the download starts from where the object has been downloaded. Therefore, it is sent
Add one more message to the Web server-where to start.
The following is a self-compiled "Browser" to transmit the request information to the Web server, starting from 2000070 bytes.
GET/down.zip HTTP/1.0
User-Agent: netfox
Value Range: bytes = 2000070-
Accept: text/html, image/GIF, image/JPEG, *; q =. 2, */*; q =. 2
Take a closer look and you will find that there is an additional row range: bytes = 2000070-
In this line, the file down.zip is uploaded starting from 2000070 bytes, and the previous bytes are not required.
After receiving the request, the server returns the following information:
206
Content-Length = 106786028
Content-range = bytes 2000070-106786027/106786028
Date = Mon, 30 Apr 2001 12:55:20 GMT
Etag = W/"02ca57e173c11: 95b"
Content-Type = application/octet-stream
Server = Microsoft-Microsoft IIS/5.0
Last-modified = Mon, 30 Apr 2001 12:55:20 GMT
Compared with the information returned by the preceding server, a new row is added:
Content-range = bytes 2000070-106786027/106786028
The Returned Code is also changed to 206, instead of 200.
With the above principles, you can program resumable data transfer.