1 Reply Latest reply on Mar 8, 2013 7:54 AM by sviluppatorefico

    Download binary data file  - Received a content type of application/zip but it contains no bytes of data

    pking

      Hi All,

       

       

      I'm trying to develop functionality to download (push to the browser) a some binary content as a file - let's assume it's a zip file.

      I have tried variety of way how to get it - but it's too tough nut to crack for me - probably I make somewhere just a stupid mistake... anyway the code gives me an ansewer:

       

      2011-03-18 11:23:56,377 ERROR [portal:UIPortletActionListener] Received a content type of application/zip but it contains no bytes of data.

       

      Refere to line: 461: http://fisheye.jboss.org/browse/gatein/portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java?hb=true

       

      Help, help .. any help ... highly appreciated,

       

       

       

       

      else if (responseObject instanceof BufferedResourceResponseWrapper) {
                      log.error("BufferedResourceResponseWrapper");
      
                      BufferedResourceResponseWrapper portletResponse = (BufferedResourceResponseWrapper) responseObject;
      
                      byte []data=new byte[]{45,56,32,56,67,78,78,67,56,45,56,67,68,69,70,71,72,73,74,75,76,77,78,79};
      
      
                      portletResponse.setContentType("application/zip");                portletResponse.setHeader("Content-disposition", "attachment; filename=\"Raw-Data.zip\"");
                      portletResponse.setContentLength(date.length);
                     
      
                      try {
      
      
                          // portletResponse.getWriter().write("this is a text",0,7);
                          // portletResponse.writeBufferedData();
                       FastBufferOutputStream os = portletResponse.getPortletOutputStream();
                           os.write(data);
                           os.flush();
                           os.close();
                           portletResponse.flushBuffer();
                           facesContext.responseComplete();
                           log.error("\nRESPONSE IS COMMITED3: " + portletResponse.getResponse().isCommitted());
                      } catch (Exception e) {
                          log.error("\nFailure : " + e.toString() + "\n");
                      }
                  }
      

       

       

      Greetings,

      Pawel