5

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Priya
  • 253
  • 1
  • 4
  • 12
  • 1
    Have you tried anything so far? If so, please post whatever you have so that the community can help better – EdmDroid Feb 09 '15 at 10:08
  • No. I have just created a service to upload a jar file. Now i want a service to download jar file – Priya Feb 09 '15 at 10:24
  • That's exactly my point. Have you done anything in the direction of making the restful service for downloading the jar? – EdmDroid Feb 09 '15 at 10:26

1 Answers1

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();
    }
pgregory
  • 2,093
  • 1
  • 12
  • 8
Priya
  • 253
  • 1
  • 4
  • 12