Priya
Priya

Reputation: 353

Spring boot service to download a file

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?

Upvotes: 5

Views: 14431

Answers (1)

Priya
Priya

Reputation: 353

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

Upvotes: 13

Related Questions