总结:从文件上传谈 策略模式运用 ,虚拟路径配置,纸上得来终觉浅,绝知此事要躬行。

单文件,多文件,base64 几种上传方式 。具体细节参考我的代码库 https://gitee.com/www.lyc.com/lyc-demo.git

   

/** * tip 小知识这里其实有多套(本地 阿里 七牛,又拍,腾讯) 实现 * 可以根据 传参不同 从容器 取对于的实现 然后管理不同的 文件服务器 * 联想策略模式 消除 if else  设计模式优雅> switch case 优雅> if else *///@Autowiredprivate FileService fileService = (FileServiceImpl) SptingUtils.getBean("fileServiceImpl");

@GetMappingpublic String index() {    return "index";}

/** * 单文件 * @param file * @param request * @return */@PostMapping("/uploads/upload1")@ResponseBodypublic ResponseResult upload1(@RequestParam("file") MultipartFile file, HttpServletRequest request) {

    String result = null;    try {        result = fileService.upload(file,request);    } catch (IOException e) {        ResponseResultFactory.fieldFail("上传失败",result);    }    return ResponseResultFactory.success("上传成功",result);}

/** * 多文件 * @param files * @return * @throws IOException */@PostMapping("/uploads/upload2")@ResponseBodypublic ResponseResult upload2(@RequestParam("file") MultipartFile[] files)  {    String result = null;    try {        result = fileService.uploads(files);    } catch (IOException e) {        ResponseResultFactory.fieldFail("上传失败",result);    }    return ResponseResultFactory.success("上传成功",result);}

/** * base64 * @param base64Image * @return * @throws IOException */@PostMapping("/uploads/upload3")@ResponseBodypublic ResponseResult upload2(String base64Image) {    String result = null;    try {        result = fileService.uploadBase64(base64Image);    } catch (IOException e) {        ResponseResultFactory.fieldFail("上传失败",result);    }    return ResponseResultFactory.success("上传成功",result);}

转载于:https://www.cnblogs.com/lyc88/articles/10988673.html

springboot 文件上传 各种姿势 解锁,策略模式简单运用相关推荐

  1. 补习系列(11)-springboot 文件上传原理

    一.文件上传原理 一个文件上传的过程如下图所示: 浏览器发起HTTP POST请求,指定请求头: Content-Type: multipart/form-data 服务端解析请求内容,执行文件保存处 ...

  2. SpringBoot文件上传源码解析

    一.SpringMVC文件上传源码分析前言(这部分我觉得原作者写的很好) 该如何研究SpringMVC的文件上传的源码呢? 研究源码并不是仅仅知道程序是怎样运行的,而应该从宏观的角度.不同的立场去看待 ...

  3. 解决Springboot文件上传报错,java.io.FileNotFoundException: D:\System\Temp\tomcat.819...00.tmp (系统找不到指定的文件。)

    Springboot文件上传,csdn上的方法无非是下面这两个: imgFile.transferTo(imageFolder); // 方法一/*** 方法二* FileUtils.copyInpu ...

  4. springboot文件上传下载实战 ——文件上传、下载、在线打开、删除

    springboot文件上传下载实战 文件上传 文件上传核心 UserFileController 文件上传测试 文件下载与在线打开 文件下载.在线打开核心 UserFileController 文件 ...

  5. springboot文件上传下载实战 —— 登录功能、展示所有文件

    springboot文件上传下载实战 创建项目 pom.xml 数据库建表与环境准备 建表SQL 配置文件 application.properties 整体架构 前端页面 登录页面 login.ht ...

  6. SpringBoot文件上传异常之提示The temporary upload location xxx is not valid

    SpringBoot文件上传异常之提示The temporary upload location xxx is not valid 参考文章: (1)SpringBoot文件上传异常之提示The te ...

  7. 文件上传绕过姿势整理

    文件上传绕过姿势整理 WAF绕过 安全狗绕过 1.绕过思路:对文件的内容,数据.数据包进行处理. 关键点在这里Content-Disposition: form-data; name="fi ...

  8. 各种文件上传绕过姿势(一)

    各种文件上传绕过姿势 **目录** 各种文件上传绕过姿势 写在前面 一.前端绕过 1.1 防护手段 1.2 绕过方法 二.检查MIME类型 2.1 防护手段 2.2 绕过方法 三.黑名单绕过(一) 3 ...

  9. SpringBoot 文件上传 通过Content-Type和文件头判断文件类型

    SpringBoot 文件上传 通过Content-Type和文件头判断文件类型 一.关于MIME MIME的全称是Multipurpose Internet Mail Extensions,即多用途 ...

最新文章

  1. mysql查询员工表中所有员工入职20个月之后的日期_Mysql基础教程
  2. TCP三次握手建立连接四次挥手断开连接
  3. 伪指令 .align 的含义
  4. stringstream的基本用法
  5. PyCharm 5 破解注册方法
  6. 海马体what where记忆推理模型
  7. IIS执行ASP程序不能调用数据库出现500错误的解决方法
  8. 激光雷达厂商速腾聚创获3亿元融资,阿里菜鸟、上汽,北汽入股
  9. Windows server 2016 部署AD(Windows 域)
  10. MDK代码格式化工具
  11. 【LeetCode】贪心算法:常见典例
  12. 微信小程序连接“萤石云”
  13. 如何用python批量下载数据_如何基于Python批量下载音乐
  14. 洛谷P2678 [NOIP2015 提高组] 跳石头
  15. vlc-for-android
  16. 关于Spring容器中定时器到时执行会出现两个线程同时执行的问题
  17. 微信公众平台如何授权第三方平台,干货到!微信公众号怎样添加第三方平台及取消授权
  18. “听觉”营销价值凸显,喜马拉雅迎来新局点
  19. random()随机数的产生方式与原理
  20. OrientDB 图状数据库示例

热门文章

  1. decimal转换为int_FPGA基础知识极简教程(10)二进制到BCD转换算法
  2. MYSQL基本知识:TRUNCATE和DELETE的区别
  3. 基于jmeter测试web接口,看完都说学会了
  4. 基于持续集成的轻量级接口自动化测试
  5. linux rec命令_文件过多时ls命令为什么会卡住?
  6. 需求跟踪矩阵模板_大连电视台采用无跟踪虚拟技术升级多套节目
  7. 华为nova2s云相册在哪里_华为反人类的用户体验
  8. 利用深度学习技术自动可靠的叶病检测(附数据+分割分类详细+公共总结)
  9. 【matlab】将几幅图片放到一个画布中
  10. 深度迁移学习在花生叶部病害图像识别中的应用