1、编写页面uploadFile.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上传文件</title>
</head>
<body>
<form action="uploadFile" method="post" enctype="multipart/form-data">
<input type="file" name="myfile">
<input type="submit" value="上传">
</form>
</body>
</html>

2、编写controller

package com.bjsxt.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import java.io.File;
import java.util.HashMap;
import java.util.Map; /**
* Created by Administrator on 2019/2/5.
*/
@RestController
public class UploadFileController { @RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
public Map<String,Object> uploadFile(MultipartFile myfile){
Map<String,Object> returnMap=new HashMap<String,Object>();
try{
myfile.transferTo(new File("e:/"+myfile.getOriginalFilename()));
returnMap.put("msg","上传成功");
}catch (Exception e){
e.printStackTrace();
returnMap.put("msg","上传失败");
}
return returnMap;
} }

3、编写启动类

package com.bjsxt;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* Created by Administrator on 2019/2/5.
*/
@SpringBootApplication
public class App { public static void main(String[] args){
SpringApplication.run(App.class,args);
}
}

4、设置上传文件的大小限制

  需要添加一个springboot的配置文件,名字为application.properties,放在resource文件夹下,添加以下内容

#设置单个文件上传的最大大小
spring.http.multipart.maxFileSize=200MB
#设置一次请求上传文件的总容量的大小
spring.http.multipart.maxRequestSize=200MB

5、启动项目即可,在浏览器中访问http://localhost:8080/uploadFile.html即可

目录结构

SpringBoot: 6.文件上传(转)的更多相关文章

  1. SpringBoot图文教程4—SpringBoot 实现文件上传下载

    有天上飞的概念,就要有落地的实现 概念+代码实现是本文的特点,教程将涵盖完整的图文教程,代码案例 文章结尾配套自测面试题,学完技术自我测试更扎实 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例 ...

  2. SpringBoot 整合文件上传 elment Ui 上传组件

    SpringBoot 整合文件上传 elment Ui 上传组件 本文章记录 自己学习使用 侵权必删! 前端代码 博主最近在学 elment Ui 所以 前端使用 elmentUi 的 upload ...

  3. springboot+web文件上传和下载

    一.首先安装mysql数据库,开启web服务器. 二.pom.xml文件依赖包配置如下: <?xml version="1.0" encoding="UTF-8&q ...

  4. SpringBoot(3) 文件上传和访问

    springboot文件上传 MultipartFile file,源自SpringMVC MultipartFile 对象的transferTo方法,用于文件保存(效率和操作比原先用FileOutS ...

  5. SpringBoot的文件上传

    先在src/main/resources下新建一个static目录用以存放html页面,简单的html页面如下 <!DOCTYPE html> <html> <head& ...

  6. springBoot的文件上传功能

    知识点: 后台:将上传的图片写入指定服务器路径,保存起来,返回上传后的图片路径(在springBoot中,参考博客:http://blog.csdn.net/change_on/article/det ...

  7. SpringBoot下文件上传与下载的实现

    原文:http://blog.csdn.net/colton_null/article/details/76696674 SpringBoot后台如何实现文件上传下载? 最近做的一个项目涉及到文件上传 ...

  8. Angular14 利用Angular2实现文件上传的前端、利用springBoot实现文件上传的后台、跨域问题

    一.angular2实现文件上传前端 Angular2使用ng2-file-upload上传文件,Angular2中有两个比较好用的上传文件的第三方库,一个是ng2-file-upload,一个是ng ...

  9. springboot 修改文件上传大小限制

    springboot 1.5.9文件上传大小限制spring:http:multipart:maxFileSize:50MbmaxRequestSize:50Mb springboot 2.0文件上传 ...

  10. SpringBoot实现文件上传

    前言参考:快速开发第一个SpringBoot应用 这篇文章会讲解如何使用SpringBoot完成一个文件上传的过程,并且附带一些SpringBoot开发中需要注意的地方 首先我们写一个文件上传的htm ...

随机推荐

  1. BCB 如何拦截TAB键消息

    最近项目中一个需求,按下Tab键,按照指定的顺序进行跳转. 在实现的过程中发现,Tab按下的时候,会让当前控件失去焦点.并跳转到其他可焦点控件 例如 TEdit,TButton 等. 究其原理,是因为 ...

  2. 百度人脸识别java html5

    1.前端thymeleaf+h5 index.html    人脸识别+定位,用的百度sdk <!DOCTYPE html> <html xmlns="http://www ...

  3. Vue入门(一)——环境搭建

    1.参考该教程装vue脚手架和创建工程 https://segmentfault.com/a/1190000008922234 附:在每个工程下cmd,执行npm install,此时工程下会多一个n ...

  4. 第一节:python读取excel文件

    写在前面: (1)Excel中数字格式int(1),读出的是float(1.0)类型,导致传参时造成不同,强制转换时,int(str(1.0))在2.7版本又会报错ValueError: invali ...

  5. Cow Hopscotch (单调队列 + DP)

    链接:https://ac.nowcoder.com/acm/contest/1113/K来源:牛客网 The cows have reverted to their childhood and ar ...

  6. BZOJ 3924 / Luogu P3345 [ZJOI2015]幻想乡战略游戏 (动态点分治/点分树)

    题意 树的结构不变,每个点有点权,每一条边有边权,有修改点权的操作,设xxx为树中一点.求∑idist(x,i)∗a[i]\sum_idist(x,i)*a[i]i∑​dist(x,i)∗a[i]的最 ...

  7. Mixed Content混合内容错误 Iframe Http页面无法访问

    问题描述 为通过安全测试, 系统升级为https, 后由于新增了接口(页面集成方式, 即第三方系统某一个界面需要嵌入到我们系统的某个页面中) 采用iframe和重定向方式都报同样的错误, 意思就是我们 ...

  8. Luogu P1951 收费站_NOI导刊2009提高(2) 二分 最短路

    思路:二分+最短路 提交:1次 题解: 二分最后的答案. $ck()$: 对于每次的答案$md$跑$s,t$的最短路,但是不让$c[u]>md$的点去松弛别的边,即保证最短路不经过这个点.最后$ ...

  9. C#中如何去掉字"/0"

    string str = "you/0are/0sweet/0"; str = str.replace("/0","")); 备忘一下

  10. mysql 日期字符串互转

    字符串转日期select str_to_date('2008-4-2 15:3:28','%Y-%m-%d %H:%i:%s');select str_to_date('2008-08-09 08:9 ...