當前位置:首頁 » 文件管理 » 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-05-02 20:51:27 瀏覽:756
腳本對線男刀 發布:2025-05-02 20:44:33 瀏覽:288
三星手機加密怎麼取消 發布:2025-05-02 20:41:56 瀏覽:727
爐石傳說怎麼換伺服器 發布:2025-05-02 20:34:31 瀏覽:646
換一個伺服器是什麼意思 發布:2025-05-02 20:24:45 瀏覽:152
搭建交易所配什麼伺服器比較好 發布:2025-05-02 20:22:27 瀏覽:812
phpiismysql安裝 發布:2025-05-02 20:05:34 瀏覽:903
方舟安卓手游怎麼玩聯機 發布:2025-05-02 19:52:19 瀏覽:202
榴槤肉存儲 發布:2025-05-02 19:51:26 瀏覽:72
java怎麼鏈接資料庫 發布:2025-05-02 19:45:42 瀏覽:269