博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ng-file-upload结合springMVC使用
阅读量:7092 次
发布时间:2019-06-28

本文共 1276 字,大约阅读时间需要 4 分钟。

  引入angular和ng-file-upload。

  前端代码

1 Upload.upload({ 2         url: 'upload', 3         fields: {'username': 'zouroto'}, // additional data to send 4         file: file 5     }).progress(function (evt) { 6         var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); 7         console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name); 8     }).success(function (data, status, headers, config) { 9         console.log('file ' + config.file.name + 'uploaded. Response: ' + data);10     });

  springMVC代码:

1 @Controller 2 public class UiController { 3  4     @ResponseStatus(HttpStatus.OK) 5     @RequestMapping(value = "/upload") 6     public void upload(@RequestParam("file") MultipartFile file, @RequestParam("username") String username ) throws IOException { 7  8         byte[] bytes; 9 10         if (!file.isEmpty()) {11              bytes = file.getBytes();12             //store file in storage13         }14 15         System.out.println(String.format("receive %s from %s", file.getOriginalFilename(), username));16     }17 18 }

  application config

1 
3
4

  maven

1 
2
commons-fileupload
3
commons-fileupload
4
1.3.1
5

 

转载地址:http://sciql.baihongyu.com/

你可能感兴趣的文章
MySQL5.6在线表结构变更(online ddl)总结
查看>>
人人都能学编程
查看>>
redis3.0.0 集群安装详细步骤
查看>>
31 天重构学习笔记22. 分解方法
查看>>
java:“泛型”的前世今生
查看>>
centos7修改字符集
查看>>
Linux下ssh连接缓慢的处理方法
查看>>
ServiceStack.Redis
查看>>
通过java得到windows的磁盘空间大小
查看>>
VTP配置
查看>>
速写几点linux方面的感悟
查看>>
sharepoint 在做好备份后,网站管理员没有权限登录
查看>>
linux ssh key免密码分发
查看>>
corosync+pacemaker+mysql+drbd构建mysql高可用集群
查看>>
docker的dockerfile文件
查看>>
前端工具 - 15个最佳的 JavaScript 表单验证库
查看>>
linux服务器安装pip命令
查看>>
JAVA游戏编程之一----IDE安装调试(3) --JAD 文件介绍--debug调试
查看>>
在CentOS 7上安装Kafka
查看>>
awk用法(二)
查看>>