Spring启动服务下载文件

时间:2015-02-09 10:07:36

标签: spring spring-boot

我想使用spring boot创建一个restful服务,它将下载位于服务器http:8080/someurl/{fileid}的jar。我该怎么办?

1 个答案:

答案 0 :(得分:13)

    @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();
    }