ng-file-upload结合springMVC使用
引入angular和ng-file-upload。
前端代码
Upload.upload({
url: 'upload',
fields: {'username': 'zouroto'}, // additional data to send
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
}).success(function (data, status, headers, config) {
console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
});
springMVC代码:
@Controller
public class UiController { @ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/upload")
public void upload(@RequestParam("file") MultipartFile file, @RequestParam("username") String username ) throws IOException { byte[] bytes; if (!file.isEmpty()) {
bytes = file.getBytes();
//store file in storage
} System.out.println(String.format("receive %s from %s", file.getOriginalFilename(), username));
} }
application config
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="5000000"/>
</bean>
maven
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
ng-file-upload结合springMVC使用的更多相关文章
- html5 file upload and form data by ajax
html5 file upload and form data by ajax 最近接了一个小活,在短时间内实现一个活动报名页面,其中遇到了文件上传. 我预期的效果是一次ajax post请求,然后在 ...
- Spring MVC-表单(Form)标签-文件上传(File Upload)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_upload.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显 ...
- jquery file upload示例
原文链接:http://blog.csdn.net/qq_37936542/article/details/79258158 jquery file upload是一款实用的上传文件插件,项目中刚好用 ...
- jQuery File Upload 单页面多实例的实现
jQuery File Upload 的 GitHub 地址:https://github.com/blueimp/jQuery-File-Upload 插件描述:jQuery File Upload ...
- jQuery File Upload done函数没有返回
最近在使用jQuery File Upload 上传图片时发现一个问题,发现done函数没有callback,经过一番折腾,找到问题原因,是由于dataType: ‘json’造成的,改为autoUp ...
- kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸
kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸
- 【转发】Html5 File Upload with Progress
Html5 File Upload with Progress Posted by Shiv Kumar on 25th September, 2010Senior Sof ...
- 用jQuery File Upload做的上传控件demo,支持同页面多个上传按钮
需求 有这么一个需求,一个form有多个文件要上传,但又不是传统的图片批量上传那种,是类似下图这种需求,一开始是用的swfupload做的上传,但是问题是如果有多个按钮的话,就要写很多重复的代码,于为 ...
- jquery file upload 文件上传插件
1. jquery file upload 下载 jquery file upload Demo 地址:https://blueimp.github.io/jQuery-File-Upload/ jq ...
- jQuery File Upload跨域上传
最近在做一个一手粮互联网项目,方案为前后端分离,自己负责前端框架,采用了Requirejs+avalonjs+jquery三个框架完成. 前后端通过跨域实现接口调用,中间也发现了不少问题,尤其是在富文 ...
随机推荐
- Shader开发工具: PVRShaman
1. A PVRShaman (.POD) workspace is provided as an example in the Chapter_10/PVR_LinearFog folder tha ...
- ASP入门(二十二)-连接数据库
ADO 简介 在 ASP 中访问数据库使用的 ADO 组件. ADO 是一项微软的技术. ADO 指 ActiveX 数据对象(ActiveX Data Objects). ADO 是微软的 Acti ...
- PyCharm安装第三方库如Requests
转载: https://blog.csdn.net/fx677588/article/details/56830929 PyCharm安装第三方库是十分方便的,无需pip或其他工具,平台就自带了这个功 ...
- 【python】insertDB1.02
#------------------------------------------------------------------------------------ # insertDB1.02 ...
- mysql生成不重复随机数(unique number generation)
转自:http://blog.csdn.net/dreamer2020/article/details/52049629 问题来源 业务中有时会遇到要生成不重复随机数的情况,例如,新生成一个商品编号. ...
- (纪录片)现代生活的秘密规则:算法 The Secret Rules of Modern Living: Algorithms
简介: The Secret Rules of Modern Living: Algorithms (2015) 导演: David Briggs主演: Marcus du Sautoy类型: 纪录片 ...
- 运用BufferedWriter把数据写入文件
public class WriteReadFiles { private static Logger log = LoggerFactory.getLogger(WriteReadFiles.cla ...
- SQLServer中char、varchar、nchar、nvarchar的区别
http://www.cnblogs.com/14lcj/archive/2012/07/08/2581234.html SQLServer中char.varchar.nchar.nvarchar的区 ...
- flume监控
Flume本身提供了http, ganglia的监控服务,而我们目前主要使用zabbix做监控.因此,我们为Flume添加了zabbix监控模块,和sa的监控服务无缝融合. 另一方面,净化Flume的 ...
- eclipse/STS 提升注解提示速度
window -- preference -- 输入content -- java -- editor -- content Assist --auto delay 选项 改为100或者更低 提示速 ...