Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 656
Priya Avatar asked Feb 09 '15 10:02

Priya


People also ask

How do I download a file from REST API?

Enter the URL of the REST Service (f.e. http://localhost:8080/rest-file-manager/resr/file/upload ) Select POST as method. Select form-data in the Body. Enter as key “attachment” of Type File.


1 Answers

    @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();
    }
like image 77
Priya Avatar answered Sep 22 '22 23:09

Priya