Spring boot service to download a file

后端 未结 1 1272
别跟我提以往
别跟我提以往 2020-12-19 12:24

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?

相关标签:
1条回答
  • 2020-12-19 13:09
        @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();
        }
    
    0 讨论(0)
提交回复
热议问题