Spring Uploading Files
1,在servlet-dispatcher.xml中添加代码
<bean
id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
/>
也可以根据需求添加相关属性
2,添加依赖jar文件
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
3、编写uploadController
@RequestMapping(value="/upload",method=RequestMethod.POST)
public String processUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file) throws IOException {
log.info("File '" + file.getOriginalFilename() + "' uploaded successfully");
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name)));
stream.write(bytes);
stream.close(); return "You successfully uploaded " + name + "!";
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}
4、使用RestClient测试上传
[2015-08-18 11/:36/:12]INFO com.kaishuhezi.api.hardware.log.controller.LogController(line/:40) -File '78a0f7dcjw1e1bvyuzt1jj.jpg' uploaded successfully
Spring Uploading Files的更多相关文章
- Spring Configuration Check Unmapped Spring configuration files found
Spring Configuration Check Unmapped Spring configuration files found 项目中有xml文件,但没有被用IntelliJ 导入现有工程时 ...
- 出现unmapped spring configuration files found
intell idea启动出现unmapped spring configuration files found提示. 把spring里面的内容都打勾.
- IntelliJ IDEA 2017 提示“Unmapped Spring configuration files found.Please configure Spring facet.”解决办法
当把自己的一个项目导入IDEA之后,Event Log提示“Unmapped Spring configuration files found.Please configure Spring face ...
- "Unmapped Spring configuration files found.Please configure Spring facet."解决办法
最近在学习使用IDEA工具,觉得与Eclipse相比,还是有很多的方便之处. 但是,当把自己的一个项目导入IDEA之后,Event Log提示"Unmapped Spring configu ...
- Uploading Files in SharePoint 2013 using CSOM and REST
http://www.shillier.com/archive/2013/03/26/uploading-files-in-sharepoint-2013-using-csom-and-rest.as ...
- IntelliJ 15 unmapped spring configuration files found
IntelliJ Spring Configuration Check 用IntelliJ 导入现有工程时,如果原来的工程中有spring,每次打开工程就会提示:Spring Configuratio ...
- Uploading files using ASP.NET Web Api
http://chris.59north.com/post/Uploading-files-using-ASPNET-Web-Api
- Unmapped Spring configuration files found.
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架后,IDEA弹出如下提示: 2.解决方案: File --> Project Structure --> M ...
- [转]Spring Boot修改最大上传文件限制:The field file exceeds its maximum permitted size of 1048576 bytes.
来源:http://blog.csdn.net/awmw74520/article/details/70230591 SpringBoot做文件上传时出现了The field file exceeds ...
随机推荐
- reason: 'unable to dequeue a cell with identifier Cell
今天在cell重用的时候出现一下错误 reason: 'unable to dequeue a cell with identifier Cell - must register ...
- 代码中函数、变量、常量 / bss段、data段、text段 /sct文件、.map文件的关系[实例分析arm代码(mdk)]
函数代码://demo.c #include<stdio.h> #include<stdlib.h> , global2 = , global3 = ; void functi ...
- [Swust OJ 552]--拼音教学(找规律)
题目链接:http://acm.swust.edu.cn/problem/0552/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- AOP 笔记
http://blog.csdn.net/Intlgj/article/details/5671248 这篇文章里面介绍的非常好,值得阅读. 这里盗用里面的两张图片 [在没有AOP之前是这样的] [使 ...
- POJ 3528 求三维凸包表面积
也是用模板直接套的题目诶 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include < ...
- POJ 3047 Fibonacci
DEBUG很辛苦,且行, 且珍惜 原代码: ans[0][0] = (ans[0][0] * a[flag][0][0] + ans[0][1] * a[flag][1][0]) % 10000; a ...
- ZOJ2849 优先队列BFS
Attack of Panda Virus Time Limit: 3 Seconds Memory Limit: 32768 KB In recent months, a computer ...
- line
小君童靴说头儿给了他一个project,实现给出屏幕上任意两个点,求出这两个点之间直线上的所有的点.觉得这个很好玩,就自己也写了一点code /* date : 2014/10/21 version ...
- PHP $_SERVER['PHP_SELF']、$_SERVER['SCRIPT_NAME'] 与 $_SERVER['REQUEST_URI'] 之间的区别
PHP $_SERVER['PHP_SELF'].$_SERVER['SCRIPT_NAME'] 与 $_SERVER['REQUEST_URI'] $_SERVER['PHP_SELF'].$_SE ...
- MVC是一种用于表示层设计的复合设计模式
它们之间的交互有以下几种: 1.当用户在视图上做任何需要调用模型的操作时,它的请求将被控制器截获. 2.控制器按照自身指定的策略,将用户行为翻译成模型操作,调用模型相应逻辑实现 ...