膜拜大神

这就是我要的滑板鞋!

    @RequestMapping(value = "/media", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> downloadFile( Long id)
throws IOException {
String filePath = "E:/" + id + ".rmvb";
FileSystemResource file = new FileSystemResource(filePath);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getFilename()));
headers.add("Pragma", "no-cache");
headers.add("Expires", "0"); return ResponseEntity
.ok()
.headers(headers)
.contentLength(file.contentLength())
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(file.getInputStream()));
}

上传文件:

    @ApiOperation(value = "添加或者替换证书", notes = "1.添加后无需重启,若证书合法,则立即生效;\n" +
"2.请确保上传的证书文件名称为license.lic,否则无效")
@PostMapping("addLicense")
public Json uploadLicense(MultipartFile file) {
if (null == file) {
return Json.fail("400", "获取上传文件失败,请检查file上传组件的名称是否正确");
} else if (file.isEmpty()) {
return Json.fail("400", "没有选择文件");
} else {
String filename = file.getOriginalFilename();
filename = licenseStorePath + filename;
File dest = new File(filename);
try {
file.transferTo(dest);
app.publishEvent(new NeedLoadLicenseEvent(this));
return Json.success("上传成功").data("filePath", filename);
} catch (IOException e) {
e.printStackTrace();
return Json.fail("500", "文件上传发生异常").data("Exception", e.getLocalizedMessage());
}
}
}

springboot#下载文件的更多相关文章

  1. springboot下载文件

    例子 /** * 下载假期模板 */ @ResponseBody @RequestMapping(value = "/downloadDolidayTemplate.do") pu ...

  2. springboot整合vue实现上传下载文件

    https://blog.csdn.net/yhhyhhyhhyhh/article/details/89888953 文章目录 springboot整合vue实现上传下载文件 1上传下载文件api文 ...

  3. Springboot(九).多文件上传下载文件(并将url存入数据库表中)

    一.   文件上传 这里我们使用request.getSession().getServletContext().getRealPath("/static")的方式来设置文件的存储 ...

  4. SpringBoot图文教程4—SpringBoot 实现文件上传下载

    有天上飞的概念,就要有落地的实现 概念+代码实现是本文的特点,教程将涵盖完整的图文教程,代码案例 文章结尾配套自测面试题,学完技术自我测试更扎实 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例 ...

  5. 使用SpringBoot实现文件的下载

    上一篇博客:使用SpringBoot实现文件的上传 已经实现了文件的上传,所以紧接着就是下载 首先还是html页面的简单设计 <form class="form-signin" ...

  6. Springboot ResponseEntity IE无法正常下载文件

    项目在google浏览器下都很nice了,但当测试到IE的时候开始出现各种问题. 项目是前端js通过URL传参fileName到后台解析返回ResponseEntity 前端代码如下: window. ...

  7. springboot项目下载文件功能中-切面-导致的下载文件失败的bug

    背景:使用spring提供的 ResponseEntity 和Resource结合,实现的下载文件功能 bug:Resource已经加载到了文件, 并且通过 ResponseEntity 构建了响应, ...

  8. Spring Boot之 Controller 接收参数和返回数据总结(包括上传、下载文件)

            一.接收参数(postman发送) 1.form表单 @RequestParam("name") String name 会把传递过来的Form表单中的name对应 ...

  9. 微信小程序上传与下载文件

    需要准备的工作: ①.建立微信小程序工程,编写以下代码. ②.通过IDE建立springboot+web工程,编写接收文件以及提供下载文件的方式,并将上传的文件相关信息记录在mysql数据库中.具体请 ...

随机推荐

  1. [BPNN]BP神经网络实现

    BP神经网络实现 以3层网络为例,Python实现: 1.代码框架 主要函数: Init函数:设定InputLayer nodes.HiddenLayer nodes.OutputLayer node ...

  2. family_to_level函数

    #include <netinet/in.h> #include <sys/socket.h> int family_to_level(int family) { switch ...

  3. 关注Ionic底部导航按钮tabs在android情况下浮在上面的处理

    Ionic是一款流行的移动端开发框架,但是刚入门的同学会发现,Ionic在IOS和android的底部tabs显示不一样.在安卓情况下底部tabs会浮上去. 如下图展示:  网上也有很多此类的解决方案 ...

  4. R语言 plot()函数

    语法: plot(x, y, ...) x,y分别是两个向量,x为横轴坐标,y为纵轴坐标 其他参数: type= "p" for points, 散点图 默认 "l&qu ...

  5. 【笔记】单步跟踪法与UPX的脱壳理解

    用PEiD查壳           UPX v0.89.6 - v1.02 / v1.05 - v1.22    这个是入门的壳,只是一个简单的压缩壳 用Stud_PE查看PE文件头信息       ...

  6. vscode 提示 Running save participants 无法保存文件

    今天vscode提示一直在running save participants...中,无法保存文件 control + shift + p打开面板后,输入Reload with extensions ...

  7. ArrayList,LinkedList,vector的区别

    1,Vector.ArrayList都是以类似数组的形式存储在内存中,LinkedList则以链表的形式进行存储. 2.List中的元素有序.允许有重复的元素,Set中的元素无序.不允许有重复元素. ...

  8. Java单例和多例

    背景:最近在学习韩老师的笔记时候发现不是很了解单例和多例,于是通过网上查找资料的方式去学习. 设计模式:最佳的实践,是软件开发人员在软件开发过程中面临一般解决方案,也就是开发的经验总结. 单例模式(S ...

  9. 获取天气预报java代码

    import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; imp ...

  10. Cisco AP-AP重置操作

    Resetting to Default Settings Using the MODE Button/spanFollow these steps to reset the access point ...