多文件上传demo
@ApiOperation(value = "批量上传", notes = "批量上传", httpMethod = "POST")
@PostMapping(value = "/upload")
public void upload(HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest=(MultipartHttpServletRequest)request;
String savePath="E:/test/"; //保证目录存在
File dir = new File(savePath);
if (!dir.isDirectory()) {
dir.mkdirs();
} Iterator<String> it = multipartRequest.getFileNames();
while (it.hasNext()) {
MultipartFile multipartFile = multipartRequest.getFile(it.next());
if (multipartFile != null) {
String originName = multipartFile.getOriginalFilename();
int subIdx = originName.lastIndexOf(".");
String suffix = originName.substring(subIdx);//文件后缀
File file;
String showName;
while (true) {
showName = UUID.randomUUID().toString().replaceAll("-", "") + suffix;//文件名称
file = new File(savePath + showName);
if (!file.exists()) {
break;
}
}
byte[] buffer = new byte[1024];
try (OutputStream os = new FileOutputStream(file);
InputStream is = multipartFile.getInputStream()){
while (is.read(buffer) != -1) {
os.write(buffer);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
多文件上传demo的更多相关文章
- WebSite 文件上传Demo
知识点: 1 <!--上传文件时: 1.必须使用Post方式来提交数据 2.必须设置表单的enctype属性 3.必须在表单中包含文件域.input t ...
- shutil模块和几种文件上传Demo
一.shutil模块 1.介绍 shutil模块是对os中文件操作的补充.--移动 复制 打包 压缩 解压 2.基本使用 1. shutil.copyfileobj(文件1, 文件2, 长度) 将文件 ...
- 基于tornado的文件上传demo
这里,web框架是tornado的4.0版本,文件上传组件,是用的bootstrap-fileinput. 这个小demo,是给合作伙伴提供的,模拟APP上摄像头拍照,上传给后台服务进行图像识别用,识 ...
- Spring文件上传Demo
package com.smbea.controller; import java.io.File; import java.io.FileOutputStream; import java.io.I ...
- java文件上传Demo
说到文件上传我们要做到: 1.引入两个包:commons-fileupload-1.2.1.jar和commons-io-1.3.2.jar 2.将form改为上传文件模式:enctype=" ...
- springMVC+uploadify3.1 文件上传 demo
uploadify3.1 api 可参考:(点击打开链接) 需要springmvc的jar包 1.upload.jsp(主要代码) <script type="text/javascr ...
- 文件上传demo
前端代码: <form action="upload.php" enctype="multipart/form-data" method="po ...
- OSS阿里云文件上传 demo。
所需jar包: aliyun-openservices-1.2.3.jar jdom-1.1.jar commons-codec-1.4.jar commons-logging-1.1.1.jar g ...
- nodejs 简单http 文件上传demo
// 这是一个简单的Node HTTP,能处理当前目录的文件 // 并能实现良种特殊的URL用于测试 // 用http://localhost:8000 或http://127.0.0.1:8000 ...
随机推荐
- luoguP4755 Beautiful Pair
https://www.luogu.org/problemnew/show/P4755 考虑分治,在 [l, r] 区间中用线段树找到最大的一个点,处理经过它的可行数对的个数,统计个数可以离线树状数组 ...
- 洛谷P5273 【模板】多项式幂函数 (加强版)
题面 传送门 题解 这里最麻烦的问题就是它不保证\(A_0=1\) 如果\(A_0>1\),那么直接整个多项式乘上个\(A_0\)的逆元,最后输出答案的时候再把答案乘上\({A_0}^m\) 如 ...
- suid, sgid,粘滞位,chattr
一. 基本含义和作用 1. SUID:当设置了SUID 位的文件被执行时,该文件将以所有者的身份运行,也就是说无论谁来执行这个文件,他都有文件所有者的特权. 2. SGID:与上面的内容类似.用于设置 ...
- css 移动端图片等比显示处理
第一次写博文,心情有点小小的激动~~~~~ 刚开始做移动端项目的时候遇到了一些优化的问题,比如,打开网页在2g或者3g的情况下加载网页,刚开始渲染的时候,遇到图片文件未请求,图片的高度会为0,当然,如 ...
- 解决You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
pip install ...出现问题 直接输入python - pip install --upgrade pip就可以了
- python高级——目录
目 录 python高级(一)—— python数据模型(特殊方法) python高级(二)—— python内置序列类型 python高级(三)—— 字典和集合(泛映射类型) python高级(四 ...
- python super()继承和多继承
class A: def __init__(self): self.n = 2 def add(self, m): print('self is {} @A.add'.format(self)) se ...
- Shiro入门资源整理
学习一个框架,查阅权威有效的资料能够事半功倍,本文收集笔者学习此框架中帮助很大的文档,希望对大家有所帮助. 对于文档类的,强烈建议看官方文档,而不是百度出来的经过网友加工或者搬运过来的资料!! shi ...
- Jmeter使用指南----压力测试工具
来源: https://blog.csdn.net/u012111923/article/details/80705141 https://www.cnblogs.com/st-leslie/p/51 ...
- Clarke Award for Imagination in Service to Society刘慈欣演讲
刘慈欣不无批评地写道(http://cn.chinadaily.com.cn/2018-11/12/content_37243853.htm): 科幻的想象力由克拉克的广阔和深远,变成赛博朋克的狭窄和 ...