Springboot 文件上传
来源:互联网 发布:js事件的写法 编辑:程序博客网 时间:2024/05/01 05:58
项目中需要用到文件上传这样一个功能,参考了网上的一篇博文成功实现:简书地址
考虑到今后可能还会用到,做个记录:
直接上代码
public class UpLoad { //图片保存路径 public static String imgResouse = "D:\\upload\\img\\"; /** * 多图上传 * * @param files */ public static List<String> imgUpLoad(List<MultipartFile> files) { List<String> urls = new ArrayList<>(); for (MultipartFile file : files) { String fileName = file.getOriginalFilename(); //图片名称格式:uuid+后缀,主要解决文件可能存在的重名覆盖问题 fileName = UUID.randomUUID().toString().replaceAll("-", "") + fileName.substring(fileName.lastIndexOf(".")); File dest = new File(imgResouse + fileName); // 检测是否存在目录 if (!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); } //文件保存 try { file.transferTo(dest);//这里我设定url仅保存文件名 urls.add(fileName); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return urls; }}这就是文件上传的方法了
阅读全文
1 0
- SpringBoot文件上传
- springboot文件上传
- SpringBoot上传文件
- springboot 文件上传
- SpringBoot之文件上传
- springboot 文件上传
- SpringBoot实现文件上传
- springboot 上传文件
- Springboot 文件上传
- SpringBoot上传文件
- SpringBoot文件上传控制
- springboot上传文件
- springboot+文件上传和下载
- springboot实现多文件上传
- springboot 文件上传大小配置
- SpringBoot轻松实现文件上传
- 15.springboot实现文件上传
- SpringBoot文件上传和下载
- windows上部署redis
- Session
- 栈和队列,以及模拟实现
- 关于hadoop配置文件的注解
- Python--从文件中读取数据
- Springboot 文件上传
- springmvc整合dubbo
- linux 编译除警
- public class与class的定义
- 删除链表中重复的节点。
- html5实现多文件的上传示例代码
- crucible 的 破解
- 易行租车系统
- string Replace