Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3058

Filedownload adds the session id to the file name

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 8.0.0
    • Fix Version/s: 8.5.2
    • Component/s: ZK Update Engine
    • Security Level: Jimmy
    • Labels:
    • Environment:

      Servers: Tomcat/Jetty/(likely others) ... with enabled url-rewriting (enabled by default)
      IE / FF / Safari?
      (Chrome is unaffected)

    • gh.sprint.customfield.default.name:
      ZK 8.5.2 S1, ZK 8.5.2 S2

      Description

      The Filedownload.save method doesn't add the suggested file name to the HTTP header "Content-Disposition".

      Code from zk 3.6.4 (Https.write):

      if (download) {
        String value = "attachment";
        final String flnm = media.getName();
        if (flnm != null && flnm.length() > 0)
          value += ";filename=\"" + URLs.encode(flnm) +'"';
        response.setHeader("Content-Disposition", value);
        //response.setHeader("Content-Transfer-Encoding", "binary");
      }
      

      Code from zk 8.0.0 (Https.write):

      if (download) {
        String value = "attachment";
        
        // Bug ZK-1257: Filedownload.save(media, filename) does not save the media as the specified filename
        StringBuffer temp = request.getRequestURL();
        final String update_uri = (String)request.getSession().getServletContext().getAttribute("org.zkoss.zk.ui.http.update-uri"); //B65-ZK-1619
        String flnm = "";
        if (update_uri != null && temp.toString().contains(update_uri + "/view")) {
          // for Bug ZK-2350, we don't specify the filename when coming with ZK Fileupload, but invoke this directly as Bug ZK-1619
      //	final String saveAs = URLDecoder.decode(temp.substring(temp.lastIndexOf("/")+1), "UTF-8");
      //	flnm = ("".equals(saveAs)) ? media.getName() : saveAs;
        } else
          flnm = media.getName();
        if (flnm != null && flnm.length() > 0)
          value += ";filename=" + encodeFilename(request, flnm);
        if (media.isContentDisposition())
          response.setHeader("Content-Disposition", value);
        //response.setHeader("Content-Transfer-Encoding", "binary");
      }
      

      The 3.6.4 version adds the file name to the HTTP header.

      The 8.0.0 only adds the file name to the HTTP header if the condition update_uri != null && temp.toString().contains(update_uri + "/view") is false. The condition is by default true because the request URL normally contains the string /zkau/view (update_uri + "/view").

        Activity

        Hide
        naarani naarani added a comment -

        hi!
        we can't reproduce it, but our customers have problemi with zk 8+ with IE and Safari because sometimes the session id is added to the file name...

        d.

        Show
        naarani naarani added a comment - hi! we can't reproduce it, but our customers have problemi with zk 8+ with IE and Safari because sometimes the session id is added to the file name... d.
        Hide
        cor3000 cor3000 added a comment -

        Steps to Reproduce

        <zk>
        	<zscript><![CDATA[
        		Filedownload.save("some content", "text/plain", "/todownload.txt");
        	]]></zscript>
        	Download starting automatically...
        </zk>
        
        1. clear your cookies
        2. open the zul file from above in IE11/Edge/FF/Safari? (Chrome doesn't have the problem)

        Actual Result

        file is downloaded with the sessionid in its name:
        e.g. todownload.txt;jsessionid=node0lhbqqq4va8b3bfcmejscz0fk3.node0

        Expected Result

        filename remains: todownload.txt

        Debug Info

        This only happens for the first request after deleting the cookies for the current host.

        Root Cause

        missing content-disposition header indicating the download file name

        Workaround

        disable url-rewriting

        add this to web.xml (since Servlet Spec 3.0):

        <session-config>
            <tracking-mode>COOKIE</tracking-mode>
        </session-config>
        

        alternative options

        Show
        cor3000 cor3000 added a comment - Steps to Reproduce <zk> <zscript> <![CDATA[ Filedownload.save( "some content" , "text/plain" , "/todownload.txt" ); ]]> </zscript> Download starting automatically... </zk> clear your cookies open the zul file from above in IE11/Edge/FF/Safari? (Chrome doesn't have the problem) Actual Result file is downloaded with the sessionid in its name: e.g. todownload.txt ;jsessionid=node0lhbqqq4va8b3bfcmejscz0fk3.node0 Expected Result filename remains: todownload.txt Debug Info This only happens for the first request after deleting the cookies for the current host. Root Cause missing content-disposition header indicating the download file name Workaround disable url-rewriting add this to web.xml (since Servlet Spec 3.0): <session-config> <tracking-mode> COOKIE </tracking-mode> </session-config> alternative options
        Hide
        rudyhuang rudyhuang added a comment -

        Fixed since 2018/06/29

        Show
        rudyhuang rudyhuang added a comment - Fixed since 2018/06/29

          People

          • Assignee:
            rudyhuang rudyhuang
            Reporter:
            famls famls
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1 day
              1d
              Remaining:
              Time Spent - 5 hours Remaining Estimate - 3 hours
              3h
              Logged:
              Time Spent - 5 hours Remaining Estimate - 3 hours
              5h

                Agile