0

I have a rest api to download a file from server ,

@Path("/file")
public class FileService {          
    @GET
    @Path("/get")
    @Produces({ MediaType.APPLICATION_OCTET_STREAM })
    public Response getFile(String filePath) {    
        File file = new File(filePath);    
        ResponseBuilder response = Response.ok((Object) file);
        response.header("Content-Disposition",
            "attachment; filename=\"file_from_server.log\"");
        return response.build();

    }    
}

How to receive the file object from the javax.ws.rs.core.Response and write the content of the file in local without using browser. I am tried below ,

InputStream in = response.readEntity(InputStream.class);

But it is not working.

  • `wget http://yourhost/file/get` –  Mar 28 '18 at 10:17
  • Possible duplicate of [what's the correct way to send a file from REST web service to client?](https://stackoverflow.com/questions/12239868/whats-the-correct-way-to-send-a-file-from-rest-web-service-to-client) – statut Mar 28 '18 at 11:47

0 Answers0