Spring Boot服务下载文件 [英] Spring boot service to download a file

查看:68
本文介绍了Spring Boot服务下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Spring Boot创建一个Restful服务,该服务将下载位于服务器http:8080/someurl/{fileid}上的jar.我该怎么办?

I want to create a restful service using spring boot which will download a jar located at the server http:8080/someurl/{fileid}. How should I do it?

推荐答案

    @RequestMapping(value = "/files/{fileID}", method = RequestMethod.GET)
    public void getFile(
        @PathVariable("fileID") String fileName, 
        HttpServletResponse response) throws IOException {
            String src= DestLocation.concat("\\"+fileName+".jar");
            InputStream is = new FileInputStream(src);
            IOUtils.copy(is, response.getOutputStream());
            response.flushBuffer();
    }

这篇关于Spring Boot服务下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆