title: Download zip file from REST web service + AngularJS
body: <p>I am using REST jersey on server side and AngularJS on client side.</p>
  
  <p>My requirement is to download the zip file requested by client for specific date range.</p>
  
  <p>Server side code: //Time being I have hardcoded one zip file for testing</p>
  
  <pre><code>@POST
      @Path("/LogRange")
      @Produces({MediaType.APPLICATION_OCTET_STREAM} )
      @Consumes({ MediaType.APPLICATION_JSON} )
      public Response getLogsBetween(@HeaderParam(HttpHeaders.AUTHORIZATION) String authorization, 
              @Context HttpServletRequest request, @Context HttpServletResponse response, LogFolders folders){
  
          StreamingOutput stream = new StreamingOutput(){
              @Override
                  public void write(OutputStream arg0) {
                      // TODO Auto-generated method stub
                      BufferedOutputStream bus = new BufferedOutputStream(arg0);
                      try {
                          File file = new File("C:\\ProgramData\\ABC\\Logfiles\\UI.zip");
                          FileInputStream fizip = new FileInputStream(file);
                          byte[] buffer2 = IOUtils.toByteArray(fizip);
                          bus.write(buffer2);
                          bus.flush();
                          bus.close();
  
                      } catch (Exception e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      }
                  }
              };
              return Response.status(Response.Status.OK).entity(stream).header("Content-Disposition","attachment; filename=\"log.zip\"").build();
  }       
  </code></pre>
  
  <p>Client side code:                   </p>
  
  <pre><code>$http({
      url : urlBase + endPoint,
      method: "POST",
      data: formData, //this is your json data string
      headers : {
          'Content-Type' : "application/json",
          'Authorization' : authCode,
      },
      responseType: 'arraybuffer'
  }).success(function(response, status, headers, config) {
  
      var blob = new Blob([response], { type: "application/zip" });
      var objectUrl = URL.createObjectURL(blob);
      window.open(objectUrl);
  
      }).error(function (data, status, headers, config) {
      //upload failed
  });
  </code></pre>
  
  <p>File get downloaded in local but it is always corrupted and displays like below.
  Please help me on how to download file properly.
  <a href="https://i.stack.imgur.com/FSpsO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FSpsO.png" alt="enter image description here"></a></p>