HTTP文件上传如何工作? [英] How does HTTP file upload work?
问题描述
< form enctype =multipart / form- dataaction =http:// localhost:3000 / upload?upload_progress_id = 12344method =POST>
< input type =hiddenname =MAX_FILE_SIZEvalue =100000/>
选择要上传的文件:< input name =uploadedfiletype =file/>< br />
< input type =submitvalue =Upload File/>
< / form>
它如何在内部发送文件?该文件是否作为数据的HTTP身体的一部分发送?在这个请求的头文件中,我没有看到与文件名相关的任何内容。
我只是想知道发送文件时HTTP的内部工作方式。 解决方案
<$ p $ p>
POST / upload?upload_progress_id = 12344 HTTP / 1.1
Host:localhost:3000
Content-Length:1325
Origin:http:// localhost:3000
...其他标题...
Content-Type:multipart / form-data; border = ---- WebKitFormBoundaryePkpFF7tjBAqx29L
------ WebKitFormBoundaryePkpFF7tjBAqx29L
Content-Disposition:form-data; name =MAX_FILE_SIZE
100000
------ WebKitFormBoundaryePkpFF7tjBAqx29L
Content-Disposition:form-data; NAME = UploadedFile的; filename =hello.o
Content-Type:application / x-object
...文件内容放在这里...
------ WebKitFormBoundaryePkpFF7tjBAqx29L -
代替表单参数的URL编码,表单参数(包括文件数据)被发送在上面的例子中,你可以看到输入 MAX_FILE_SIZE $ c $在窗体中设置值,以及包含文件数据的部分。文件名是
Content-Disposition
标题的一部分。
完整的详细信息是这里。
When I submit a simple form like this with a file attached:
<form enctype="multipart/form-data" action="http://localhost:3000/upload?upload_progress_id=12344" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
How does it send the file internally? Is the file sent as part of the HTTP body as data? In the headers of this request, I don't see anything related to the name of the file.
I just would like the know the internal workings of the HTTP when sending a file.
Let's take a look at what happens when you select a file and submit your form (I've truncated the headers for brevity):
POST /upload?upload_progress_id=12344 HTTP/1.1
Host: localhost:3000
Content-Length: 1325
Origin: http://localhost:3000
... other headers ...
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryePkpFF7tjBAqx29L
------WebKitFormBoundaryePkpFF7tjBAqx29L
Content-Disposition: form-data; name="MAX_FILE_SIZE"
100000
------WebKitFormBoundaryePkpFF7tjBAqx29L
Content-Disposition: form-data; name="uploadedfile"; filename="hello.o"
Content-Type: application/x-object
... contents of file goes here ...
------WebKitFormBoundaryePkpFF7tjBAqx29L--
Instead of URL encoding the form parameters, the form parameters (including the file data) are sent as sections in a multipart document in the body of the request.
In the example above, you can see the input MAX_FILE_SIZE
with the value set in the form, as well as a section containing the file data. The file name is part of the Content-Disposition
header.
The full details are here.
这篇关于HTTP文件上传如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!