I am new to Jersey / JAX -RS implementation. The following is the client code for downloading the file:
Client client = Client.create(); WebResource wr = client.resource("http://localhost:7070/upload-0.0.1-SNAPSHOT/rest/files/download"); Builder wb=wr.accept("application/json,application/pdf,text/plain,image/jpeg,application/xml,application/vnd.ms-excel"); ClientResponse clientResponse= wr.get(ClientResponse.class); System.out.println(clientResponse.getStatus()); File res= clientResponse.getEntity(File.class); File downloadfile = new File("C://Data/test/downloaded/testnew.pdf"); res.renameTo(downloadfile); FileWriter fr = new FileWriter(res); fr.flush();
My server code:
@Path("/download") @GET @Produces({"application/pdf","text/plain","image/jpeg","application/xml","application/vnd.ms-excel"}) public Response getFile() { File download = new File("C://Data/Test/downloaded/empty.pdf"); ResponseBuilder response = Response.ok((Object)download); response.header("Content-Disposition", "attachment; filename=empty.pdf"); return response.build(); }
In my client code, I get the answer as 200 OK, but I canβt save the file to my hard drive. In the line below, I mention the path and place where the files should be saved. Not sure what is going wrong here, any help would be appreciated. Thanks in advance.
File downloadfile = new File("C://Data/test/downloaded/testnew.pdf");
source share