博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot上传图片
阅读量:7088 次
发布时间:2019-06-28

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

  hot3.png

一:使用Spring Boot默认上传组件

@RequestMapping(value="/upload", method=RequestMethod.POST, consumes = {"multipart/form-data"})	public @ResponseBody String uploadFileTest(@RequestParam("file") MultipartFile file) {		System.out.println(" file name = "+ file.getOriginalFilename()+", file size = "+ file.getSize());		return "OK";	}

控制台输出

file name = 网址解析.txt, file size = 1541

二:使用Apache Commons FileUpload组件上传

  1. 关闭Spring Boot 默认配置

spring.http.multipart.enabled=false

@RequestMapping(value="/upload", method=RequestMethod.POST, consumes = {"multipart/form-data"})	public @ResponseBody String uploadFileTest() throws Exception {		ServletFileUpload upload = new ServletFileUpload();        FileItemIterator fileIterator = upload.getItemIterator(this.httpRequest);        while (fileIterator.hasNext()) {            FileItemStream item = fileIterator.next();            System.out.println(" file name = "+item.getName());        }		return "OK";	}

控制台输出

file name = 网址解析.txt

转载于:https://my.oschina.net/meibug/blog/1557598

你可能感兴趣的文章
Android广播机制分析
查看>>
Android ADB工具-截图和录制视频(五)
查看>>
配置docker官方源并用yum安装docker
查看>>
PHP/Javascript 数组定义 及JSON中的使用 ---OK
查看>>
php中urldecode()和urlencode()起什么作用啊
查看>>
UVA 11542 Square 高斯消元 异或方程组求解
查看>>
Nginx的内部(进程)模型
查看>>
基于设备树的controller学习(1)
查看>>
递归--练习1--noi3089爬楼梯
查看>>
慢慢过渡到个人博客
查看>>
深度学习 Deep Learning UFLDL 最新Tutorial 学习笔记 4:Debugging: Gradient Checking
查看>>
【转】spring boot web相关配置
查看>>
oc53--autorelease注意事项
查看>>
sigmod2017.org
查看>>
MongoDB集群运维笔记
查看>>
Python代码优化及技巧笔记(一)
查看>>
Caused by: java.lang.NoClassDefFoundError: org/apache/neethi/AssertionBuilderFactory
查看>>
Ocelot 集成Butterfly 实现分布式跟踪
查看>>
(转)各种语言写网络爬虫有什么优点缺点
查看>>
如何用公式编辑器打带圈加号
查看>>