当前位置:首页 » 文件管理 » http表单上传文件

http表单上传文件

发布时间: 2025-02-14 19:34:11

Ⅰ 关于使用Springmvc的MultipartHttpServletRequest来获得表单上传文件的问题,万分感谢~

try {
//下面这句必须加,不然报错
MultipartResolver resolver = new CommonsMultipartResolver(request.getSession().getServletContext());
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//获取一起跟文件传过来的其他参数值
String id = multipartRequest.getParameter("id");
//获取上传上来的文件
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()){
MultipartFile file = entry.getValue();
String fileName = file.getOriginalFilename();
System.out.println(fileName);
String path = "C:\\Users\\Administrator\\Desktop" + File.separator + fileName;
file.transferTo(new File(path));
}

} catch (Exception e) {
e.printStackTrace();
}

Ⅱ 怎么用http上传一个文件到服务器 python

首先,标准HTTP协议对上传文件等表单的定义在这里:wwwietforg/rfc/rfc1867txt 大概数据包格式如下:

单文件:

Content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="field1"

Joe Blow
--AaB03x
content-disposition: form-data; name="pics"; filename="file1.txt"
Content-Type: text/plain

... contents of file1.txt ...
--AaB03x--
多文件:

Content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="field1"

Joe Blow
--AaB03x
content-disposition: form-data; name="pics"
Content-type: multipart/mixed, boundary=BbC04y

--BbC04y
Content-disposition: attachment; filename="file1.txt"
其次,python上传文件的几种方法:

1 自己封装HTTP的POST数据包:http//stackoverflowcom/questions/680305/using-multipartposthandler-to-post-form-data-with-python

import httplibimport mimetypesdef post_multipart(host, selector, fields, files): content_type, body = encode_multipart_formdata(fields, files) h = httplib.HTTP(host) h.putrequest('POST', selector) h.putheader('content-type', content_type) h.putheader('content-length', str(len(body))) h.endheaders() h.send(body) errcode, errmsg, headers = h.getreply() return h.file.read() def encode_multipart_formdata(fields, files): LIMIT = '----------lImIt_of_THE_fIle_eW_$' CRLF = '\r\n' L = [] for (key, value) in fields: L.append('--' + LIMIT) L.append('Content-Disposition: form-data; name="%s"' % key) L.append('') L.append(value) for (key, filename, value) in files:

热点内容
安卓手机高刷在哪里 发布:2025-07-02 10:43:02 浏览:342
爱奇艺iphone缓存 发布:2025-07-02 10:38:00 浏览:841
南方次元的解压 发布:2025-07-02 10:31:32 浏览:246
叶祖新编程 发布:2025-07-02 10:29:06 浏览:400
k4在哪里下载安卓 发布:2025-07-02 10:15:32 浏览:909
魔兽脚本破解版 发布:2025-07-02 10:15:30 浏览:995
锋云7800服务器无网络怎么办 发布:2025-07-02 10:03:53 浏览:1000
安卓哪个版本可以安装sd卡 发布:2025-07-02 09:58:09 浏览:984
存储包下行流量包 发布:2025-07-02 09:49:00 浏览:364
固态主控算法 发布:2025-07-02 09:38:27 浏览:12