spring html5 拖拽上传多文件
注:这仅仅是一个粗略笔记。有些代码可能没用。兴许会再更新一个能够使用的版本号。不足之处,敬请见谅。
1。spring环境搭建,这里使用的是spring3的jar,须要同一时候引入common-IO 和common-fileupload的jar包。
1.1spring.XXX.xml文件配置bean
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="${web.maxUploadSize}" />
</bean>
value="xxxx"依据实际情况改动。
2.html表单
<form id="uploadForm" action="data/myData4PipeiUpload" method="post" enctype="multipart/form-data">
<div class="upload_box">
<div class="upload_main">
<div class="upload_choose">
<span id="fileDragArea" class="upload_drag_area">请将文件拖拽至此处上传</span>
<input id="fileImage" size="30" name="fileselects[]" multiple="multiple" type="file">
</div>
<div id="preview" class="upload_preview"></div>
</div> <div id="uploadInf" class="upload_inf"></div>
</div>
<div class="upload_box">
文件名2:
<input name="fileFieName" id="fileFieName" />
</div>
<DIV class="modal-footer">
<BUTTON class="btn btn-primary" type="submit" id="submitBut3" data-dismiss="modal">上传数据文件</BUTTON>
</DIV>
</form>
2.1除了普通上传的一些格式要求之外。这里要注意多文件须要name=“XXX[]” multiple=“multiple"
<input id="fileImage" size="30" name="fileselects[]" multiple="multiple" type="file">
2.2这里使用了upload.js和zxxFile.js。去配置相关參数
3.后台代码编写两种方式。
3.1
@RequestMapping(value = "/myData4PipeiUpload", method = RequestMethod.POST)
public void handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
// 转型为MultipartHttpRequest:
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<MultipartFile> singleFiles = multipartRequest.getFiles("fileselects[]"); if(singleFiles!=null&&singleFiles.size()>0){
for(MultipartFile file: singleFiles){
// 获得文件名称:
String filename = file.getOriginalFilename();
// 获得输入流:
InputStream input = file.getInputStream();
// 写入文件
// 或者:
File source = new File("d:/dd/"+filename);
file.transferTo(source);
}
}
}
注意參数的获取要使用fileselects[]去获取列表
3.2,直接将请求名称写入到@requestParam
@RequestMapping(value = "/myData4PipeiUpload", method = RequestMethod.POST)
public void handleRequest(@RequestParam("fileselects[]") MultipartFile[] files,HttpServletRequest request,
HttpServletResponse response) throws Exception { if(files!=null&&files.length>0){
for(MultipartFile file: files){
// 获得文件名称:
String filename = file.getOriginalFilename();
// 获得输入流:
InputStream input = file.getInputStream();
// 写入文件 // 或者:
File source = new File("d:/dd/"+filename);
file.transferTo(source);
}
}
}
这样子就能够再进行兴许的操作。
spring html5 拖拽上传多文件的更多相关文章
- [开源应用]利用HTTPHandler+resumableJs+HTML5实现拖拽上传[大]文件
前言: 大文件传输一直是技术上的一大难点.文件过大时,一些性提交所有的内容进内存是不现实的.大文件带来问题还有是否支持断点传输和多文件同时传输. 本文以resumableJs为例,介绍了如何在ASP. ...
- 基于 jq 实现拖拽上传 APK 文件,js解析 APK 信息
技术栈 jquery 文件上传:jquery.fileupload,github 文档 apk 文件解析:app-info-parser,github 文档 参考:前端解析ipa.apk安装包信息 - ...
- html5 拖拽上传文件时,屏蔽浏览器默认打开文件
参考: https://www.cnblogs.com/kingsm/p/9849339.html
- html5实现拖拽上传
<html><head> <meta http-equiv="Content-Type" content="text/html; chars ...
- html5拖拽事件 xhr2 实现文件上传 含进度条
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- HTML5应用之文件拖拽上传
使用HTML5的文件API,可以将操作系统中的文件拖放到浏览器的指定区域,实现文件上传到服务器.本文将结合实例讲解HTML5+jQuery+PHP实现拖拽上传图片的过程,来看下HTML5的魅力吧. H ...
- html5 文件拖拽上传
本文首先发表在 码蜂笔记 : http://coderbee.net/index.php/web/20130703/266 html5 文件拖拽上传是个老话题了,网上有很多例子,我一开始的代码也是网 ...
- [转]人人网首页拖拽上传详解(HTML5 Drag&Drop、FileReader API、formdata)
人人网首页拖拽上传详解(HTML5 Drag&Drop.FileReader API.formdata) 2011年12月11日 | 彬Go 上一篇:给力的 Google HTML5 训练营( ...
- 原生API实现拖拽上传文件实践
功能: 拖拽上传文件.图片,上传的进度条,能够同时上传多个文件. 完整的demo地址:https://github.com/qcer/FE-Components/tree/master/QDrag 涉 ...
随机推荐
- ruby语言仅仅是昙花一现
Ruby语言本身存在非常久了,在国内一直没火过.非常多人仅仅是知道有这样的语言,会的人少之又少.不论什么一种语言坚持十来年的发展,变得越来越好,一定有它不平常的地方.不能任意的去比較语言本身的好与坏. ...
- scala 函数编程
scala 函数编程 Effective Scala.pdf: http://www.t00y.com/file/76767869 Functional_Programming_in_Scal ...
- 怎么获取Spring的ApplicationContext
在 WEB 开发中,可能会非常少须要显示的获得 ApplicationContext 来得到由 Spring 进行管理的某些 Bean, 今天我就遇到了,在这里和大家分享一下, WEB 开发中,怎么获 ...
- HDU1035深度搜索
/* HDU1035 意甲冠军: 给定一个字符矩阵,N S W E分别代表向上,下,剩下,进 模拟搜索,推断: 若能走出字符矩阵.则Yes,输出步数 若走不出矩阵,那么必然有圈存在,必然在矩阵中存在一 ...
- HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...
- nginx 源码安装
安装环境: 操作系统:Ubuntu 12.04 Nginx: V1.4.2 PCRE: V8.33 zlib: V1.2.8 下载上述源包到当前用户主目录(本机:/hom ...
- 国内国外MD5在线解密站点
-http://www.cmd5.com/english.aspx (457,354,352,282) - http://www.md5crack.com - http://www.hashcheck ...
- CrossBridge介绍
CrossBridge介绍 作者:chszs,转载需注明.博客主页: http://blog.csdn.net/chszs CrossBridge是Adobe FlasCC的开源版本,它提供了一个完整 ...
- Egret是一套完整的HTML5游戏开发解决方案
Egret是一套完整的HTML5游戏开发解决方案.Egret中包含多个工具以及项目.Egret Engine是一个基于TypeScript语言开发的HTML5游戏引擎,该项目在BSD许可证下发布.使用 ...
- WebKit爬虫
https://github.com/emyller/webkitcrawler 一个开源的项目,可以快速入门. http://spiderformysql.com/ http://crawl.gro ...