多图片上传-springboot
来源:互联网 发布:刺客信条4a卡优化 编辑:程序博客网 时间:2024/06/02 06:05
多图片上传-springboot
@RequestMapping(value = "save.do")@ResponseBodypublic String save(HttpServletRequest request, HttpServletResponse response, ModelMap model,@RequestParam("logos")MultipartFile[] files) {
List<String> logos;//if(files!=null) {//for(int i=0;i<files.length;i++) {//MultipartFile file = files[i];//// 获取文件名// String fileName = file.getOriginalFilename();// log.info("上传的文件名为:" + fileName);// String prefixName = fileName.substring(0, fileName.lastIndexOf("."));// String suffixName = fileName.substring(fileName.lastIndexOf("."));// log.info("上传的后缀名为:" + suffixName);// // File dest = new File(filePath + fileName);// // 检测是否存在目录// if (!dest.getParentFile().exists()) {// dest.getParentFile().mkdirs();// }// if(dest.exists()) {// //已有同名文件
// // // fileName = prefixName + UUID.randomUUID() + suffixName;// dest = new File(filePath + prefixName+System.currentTimeMillis()+suffixName);// }// try {// file.transferTo(dest);// //获取访问路径// logos.add(dest.getPath());// } catch(Exception e) {// e.printStackTrace();// result = "文件上传失败!";// }// }// }// String tempStr = logos.toString();//[string1,string2]// vo.setLogo(tempStr.substring(1, tempStr.length()-1));//string1,string2}
//解决中文问题,liunx下中文路径,图片显示问题@RequestMapping("upload.do")
public String save(HttpServletRequest request, @RequestParam MultipartFile[] myfile) throws IOException {
List<Long> ids = new ArrayList<>();
if (myfile.length==0) {
return null;
} else {
for (MultipartFile multipartFile : myfile) {
String contentType = multipartFile.getContentType();
if (StringUtils.endsWithAny("image/jpeg", "image/gif","image/jpeg","image/png",contentType)) {
InputStream inputStream = multipartFile.getInputStream();
String originalFilename = multipartFile.getOriginalFilename();
Date date=new Date();
String dateStr = DateUtils.getDateStr(date);
FileImgVo fileImgVo=new FileImgVo();
FileInfoVo fileInfoVo=new FileInfoVo();
fileInfoVo.setFileDesc("");
String fileRelativePath="img/"+dateStr;
fileInfoVo.setFileRelativePath(fileRelativePath);
fileInfoVo.setFileSaveName(UUID.randomUUID().toString());
fileInfoVo.setFileExtensionName(originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length()));
fileInfoVo.setFileName(originalFilename);
Long size = multipartFile.getSize();
fileInfoVo.setFileSize(new Double(size));
BufferedImage bufferedImage = ImageIO.read(inputStream);
if (bufferedImage!=null) {
fileImgVo.setImgFileHight(bufferedImage.getHeight());
fileImgVo.setImgFileWidth(bufferedImage.getWidth());
}
File file=new File(fileLocation+fileRelativePath);
if (!file.exists()) {
file.mkdirs();
}
File target=new File(file, fileInfoVo.getFileSaveName()+fileInfoVo.getFileExtensionName());
String format=contentType.substring(contentType.lastIndexOf("/")+1, contentType.length());
try {
ImageIO.write(bufferedImage, format, target);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//文件id
ids.add(id);
}
}
}
return StringUtils.join(ids, ",");
}
阅读全文
0 0
- 多图片上传-springboot
- springboot 单个input多图片上传
- SpringBoot使用Ckediter上传图片
- Springboot restTempate POST 上传图片
- springboot\maven 添加上传图片、三级联动
- 上传图片,Not allowed to load local resource,springboot上传
- springboot实现多文件上传
- SpringBoot上传
- Springboot 之 多文件上传-知识林
- Java Springboot结合FastDFS实现文件上传以及根据图片url将图片上传至图片服务器
- SpringBoot:spring boot文件上传【多文件上传】
- 多图片上传
- webwork 多图片上传
- Struts 多图片上传
- 多图片上传实现
- ASP 多图片上传
- 多图片上传
- 多张图片上传
- 笔记(五)
- B. Wrath (思路题目)
- 多线程编程之pthread_create函数应用
- KM算法(奔小康赚大钱 )
- 学习笔记DL008:概率论,随机变量,概率分布,边缘概率,条件概率,期望、方差、协方差
- 多图片上传-springboot
- Linnux 安装SSH服务
- SharePoint Online 创建资产库
- 为什么ElasticSearch要在7.X版本去掉type?
- iOS OS X 和 iOS 中的多线程技术-2 (performSelectors)
- 超链接 a href 提交表单通过get/post方式
- Cocoa深入学习:NSOperationQueue、NSRunLoop和线程安全
- 什么是尾递归?
- 亏损数亿,阿里也要强推99元白菜价智能音箱!背后逻辑到底是啥?