rest api to download a file returns contents of file as a response without downloading it

Questions:
    @GET
        @Path("/{loginId}")
        @Produces(MediaType.APPLICATION_OCTET_STREAM)
        public Response downloadExportedFile(@PathParam("loginId") String loginId) {
                File file = new File("D://abc.txt");
            Response.ResponseBuilder response = Response.ok((Object) file);
            response.header("Content-Disposition", "attachment; filename=newfile.txt");
response.type(MediaType.APPLICATION_OCTET_STREAM_TYPE);
            return response.build();
        }

This gives response as a content of file and not downloading it

Answers:



Need Help? Chat with us