Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    save external binary data

    My SmartGWT application connects to external web-application, which generates jasper report in XLS format. This web-application returns binary data (XLS file) or error message, therefore I cannot use just Window.open feature from GWT. How can I offer save dialog with downloaded "rawData"?

    Code:
    RPCRequest req = new RPCRequest();
    req.setActionURL("http://myservlet/");
    RPCManager.sendRequest(req, new RPCCallback()
    {
      @Override
      public void execute(RPCResponse response, Object rawData, RPCRequest request)
      {
        String contentType = ((String)response.getHttpHeaders().get("Content-Type"));
        
        // if error msg
        if (contentType != null && contentType.contains("text/html"))
        {
          // show error msg
          SC.info("Error message: " + rawData);    
        }
        else
        {
          // want to save downloaded file (rawData)
        }
      }
    });

    #2
    You have to set the content-disposition in your servlet:

    Code:
    servletResponse.setHeader("Content-Disposition",
    				"attachment; filename=\"" + filenameAsString
    						+ ".xls\"; filename*=" + Charsets.UTF_8.name() + "''" + encodedFilename
    						+ ".xls");
    And don't use an RPCRequest but a DMI.

    Comment

    Working...
    X