1,在servlet-dispatcher.xml中添加代码

<bean
id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
/>


也可以根据需求添加相关属性

<property name="maxUploadSize" value="2097152"></property> 
 

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的更多相关文章

  1. Spring Configuration Check Unmapped Spring configuration files found

    Spring Configuration Check Unmapped Spring configuration files found 项目中有xml文件,但没有被用IntelliJ 导入现有工程时 ...

  2. 出现unmapped spring configuration files found

    intell idea启动出现unmapped spring configuration files found提示. 把spring里面的内容都打勾.

  3. IntelliJ IDEA 2017 提示“Unmapped Spring configuration files found.Please configure Spring facet.”解决办法

    当把自己的一个项目导入IDEA之后,Event Log提示“Unmapped Spring configuration files found.Please configure Spring face ...

  4. "Unmapped Spring configuration files found.Please configure Spring facet."解决办法

    最近在学习使用IDEA工具,觉得与Eclipse相比,还是有很多的方便之处. 但是,当把自己的一个项目导入IDEA之后,Event Log提示"Unmapped Spring configu ...

  5. 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 ...

  6. IntelliJ 15 unmapped spring configuration files found

    IntelliJ Spring Configuration Check 用IntelliJ 导入现有工程时,如果原来的工程中有spring,每次打开工程就会提示:Spring Configuratio ...

  7. Uploading files using ASP.NET Web Api

    http://chris.59north.com/post/Uploading-files-using-ASPNET-Web-Api

  8. Unmapped Spring configuration files found.

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架后,IDEA弹出如下提示: 2.解决方案: File --> Project Structure --> M ...

  9. [转]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 ...

随机推荐

  1. java基础知识----IO篇

    写在前面:本文章基本覆盖了java IO的所有内容.java新IO没有涉及.文章依然以样例为主,由于解说内容的java书非常多了,我觉的学以致用才是真.代码是写出来的,不是看出来的. 最后欢迎大家提出 ...

  2. android取得所在位置的经纬度

    android提供了LocationManager来取得位置,用LocationListener来监听位置的变化 先做一些初始化工作: /** latitude and longitude of cu ...

  3. linux修改shell为zsh

    以前使用的bash,如果目录很长,那么整个路径都被占满了. 询问一下一位大牛,答曰:zsh. 安装:ubuntu下sudo apt-get install zsh 修改默认登录shell: $chsh ...

  4. mvc中的几个数据传递

    1.ViewData对象 ViewBagData是一种字典集合数据同时属于视图基类和控制器基类的属性. 实例: //控制器 public class HomeController:Controller ...

  5. 转:什么是 HTTP Headers?

    什么是HTTP Headers HTTP是“Hypertext Transfer Protocol”的所写,整个万维网都在使用这种协议,几乎你在浏览器里看到的大部分内容都是通过http协议来传输的,比 ...

  6. Install TightVNC Server in RHEL/CentOS and Fedora to Access Remote Desktops

    Virtual Networking Computing (VNC) is a Kind of remote sharing system that makes it possible to take ...

  7. [置顶] 如何判断两个IP大小关系及是否在同一个网段中

    功能点  判断某个IP地址是否合法 判断两个IP地址是否在同一个网段中 判断两个IP地址的大小关系 知识准备 IP协议 子网掩码 Java 正则表达式 基本原理 IP地址范围 0.0.0.0- 255 ...

  8. UNIX网络编程——网络数据包检测

    网络数据包检测 数据包捕获(sniffer):是指在网络上进行数据收集的行为,需要通过网卡来完成. 三种访问方式: BSD Packet Filter(BPF) SVR4 Datalink Provi ...

  9. svn:怎样批量删除.svn文件

    怎样批量删除.svn文件 使用SVN工具的时候会生成一些以“svn”作为后缀的文件,而且每个文件夹下都有,如果想删除这些.svn文件夹,通过手动删除的渠道是很繁琐的事情. 通过以下的简单步骤可以在右键 ...

  10. ACM 做题过程中的一些小技巧。

    ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long l ...