Announcement

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

    SmartGWT 2.0 File Download issue

    Hi there,

    Apologies but I've searched the forum and cannot find an answer to this particular problem.

    - I've got a servlet streaming files.
    - If I go to it's URL directly, I get the desired "Save file as" browser popup.

    I found an example of what I'm looking for here: http://www.smartclient.com/smartgwtee/showcase/#excel_export
    If you click export, it downloads the file. However I'm not using SmartGWT EE.

    In my SmartGWT application, nothing seems to happen when I send a request to the same URL.

    I've tried it a number of ways. None of which work. Here are my attempts:

    Attempt 1 (using a hidden frame):
    Code:
            HTMLPane hiddenFrame = new HTMLPane();
            hiddenFrame.setWidth(100); //would set to 1 after tests
            hiddenFrame.setHeight(100);//would set to 1 after tests
            parent.addMember(hiddenFrame);
            hiddenFrame.setIFrameURL(url);
    Attempt2 (using the RPCManager):
    Code:
            RPCRequest req = new RPCRequest();
            req.setActionURL(url);
            RPCCallback callback = new RPCCallback() {
                public void execute(RPCResponse response, Object rawData, RPCRequest request) {
                    SC.say("File downloaded!");
                }
            };
            RPCManager.sendRequest(req, callback);
    The first attempt freezes the application, and eventually garbage is displayed in the 100x100 iframe.

    The second attempt fires the callback method almost instantly, but no file downloaded.

    Is there something I'm missing? If I go to the URL directly, the file does not open inline, it asks me to download, so I am sure the servlet is OK.

    Thanks in advance
    Alan

    #2
    It's not clear where the problem is given this information, but be sure to set the HTTP header "Content-Disposition: Attachment" server-side if you want a Save As.. dialog, also, if you trigger it via RPCManager, set transport to "hiddenFrame" (xmlHttpRequests cannot cause file download).

    Comment


      #3
      Hi there,

      thanks for the quick reply. I can confirm that I have set "Attachment" in my header.

      I also set the transport to HiddenFrame in the RPCRequest, but to no avail.

      Does anybody have a working example of some code which produces a "Save as" dialog?

      Comment


        #4
        I am firing this file download code from an onClick event on an icon in a grid.

        I just figured out a way to make it work. I wrapped the icon in "<a href" tags, with the URL pointing at the file, and the "Save as.." dialog pops up now.

        However it's a very untidy way of doing it.

        This must be a fairly common thing that many people have encountered, no?

        Comment


          #5
          Yes, and it's solved the way we explained (multiple times a day in fact :). It's unclear why it wasn't working for you, but it's a known working approach.

          Comment


            #6
            OK I've gone ahead with the "<a href=...>" wrapper around my icons, pointing them at the file servlet, and this seems to work OK.

            If anyone manages to get this working via RPCManager.sendRequest, please post a snippet of your code. :)

            I am wondering now how to make a Button work, because I can't wrap that in a "<a>" tag...

            hmmm.....

            Comment


              #7
              Can you let me know how you can set transport to hiddenframe on client side? From RPCTransport's doc page, it says that it's availabe for SmartClient Server only.

              HIDDENFRAME

              public static final RPCTransport HIDDENFRAME

              Available with SmartClient Server only. An HTML form is dynamically assembled that targets a hidden IFRAME. This mechanism is supported on all browsers and cannot be disabled by end users.
              If using the SmartClient Server and using 'Server-side dat integration'), the "hiddenFrame" transport is automatically used for all RPCManager and DataSource requests if the "xmlHttpRequest" transport is not available.

              Cannot be used to target cross-domain URLs directly.

              Comment

              Working...