HTTP文件上传如何工作?

编程入门 行业动态 更新时间:2024-10-23 15:20:05
本文介绍了HTTP文件上传如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

< 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

完整的详细信息是这里。

When I submit a simple form like this with a file attached:

<form enctype="multipart/form-data" action="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: 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文件上传如何工作?

本文发布于:2023-11-28 15:36:12,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件上传   工作   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!