jersey
  1. jersey
  2. JERSEY-759

File upload is broken with IE 6 and IE 7: Backslashes in Content-Disposition filename

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 1.14, 2.0-m08, 2.0
    • Component/s: None
    • Labels:
      None

      Description

      The closest existing report that I could find was on nabble:
      http://jersey.576304.n2.nabble.com/Jersey-truncating-the-slashes-from-the-uploaded-file-name-td5984041.html

      IE sends non-standard conforming (bug surrise, eh?) filename:
      -----------------------------7db13314200d0
      Content-Disposition: form-data; name="file"; filename="C:\tmp\Ext.js"
      Content-Type: application/octet-stream

      What my application gets when reading the filename is "C:tmpExt.js"

      Apparently (from reading the forum thread mentioned above) this bug has been around since Jersey 1.3 at least.

        Activity

        Hide
        reschke added a comment -

        For the record: Martin's analysis is correct. I wonder whether somebody has bothered to report this bug to Microsoft???

        Show
        reschke added a comment - For the record: Martin's analysis is correct. I wonder whether somebody has bothered to report this bug to Microsoft???
        Hide
        nabizamani added a comment -

        For the record: as i said i am fine with martin's implementation and i prefer his implementation compared to whatever Apache Commons FileUpload/IO is doing...
        so please don't get me wrong... i believe that microsoft knows about that "feature" but i guess they are just not as agile as martin when it comes to bug fixing

        Show
        nabizamani added a comment - For the record: as i said i am fine with martin's implementation and i prefer his implementation compared to whatever Apache Commons FileUpload/IO is doing... so please don't get me wrong... i believe that microsoft knows about that "feature" but i guess they are just not as agile as martin when it comes to bug fixing
        Hide
        Martin Matula added a comment -

        Forward-ported to 2.0 as well.

        Show
        Martin Matula added a comment - Forward-ported to 2.0 as well.
        Hide
        nabizamani added a comment -

        although a little late:
        tested with IE8 on Win7 successfully. thanks you!

        Show
        nabizamani added a comment - although a little late: tested with IE8 on Win7 successfully. thanks you!
        Hide
        kokowin added a comment - - edited

        Hi help me solve how to Instantiate with this >>

        /**

        • Instantiate an unnamed new {@link FormDataBodyPart}

          with <code>mediaType</code> of <code>text/plain</code>

        • and setting the flag for applying the fix for erroneous file name value if content disposition header of
        • messages coming from MS Internet Explorer (see <a href="http://java.net/jira/browse/JERSEY-759">JERSEY-759</a>).
        • @param fileNameFix If set to <code>true</code>, header parser will not treat backslash as an escape character
        • when retrieving the value of <code>filename</code> parameter of
        • <code>Content-Disposition</code> header.
          */
          public FormDataBodyPart(boolean fileNameFix) { super(); this.fileNameFix = fileNameFix; }

        // my code
        for (FormDataBodyPart file : files) {
        boolean childSuccess = saveFile(file, path, channel);
        if (!childSuccess)

        { success = false; return success; }

        }

        private boolean saveFile(FormDataBodyPart file, String path, ChannelSftp sftpChannel)

        { InputStream is = file.getValueAs(InputStream.class); String fileName = file.getFormDataContentDisposition().getFileName(); . . . return boolean; }
        Show
        kokowin added a comment - - edited Hi help me solve how to Instantiate with this >> /** Instantiate an unnamed new {@link FormDataBodyPart} with <code>mediaType</code> of <code>text/plain</code> and setting the flag for applying the fix for erroneous file name value if content disposition header of messages coming from MS Internet Explorer (see <a href="http://java.net/jira/browse/JERSEY-759"> JERSEY-759 </a>). @param fileNameFix If set to <code>true</code>, header parser will not treat backslash as an escape character when retrieving the value of <code>filename</code> parameter of <code>Content-Disposition</code> header. */ public FormDataBodyPart(boolean fileNameFix) { super(); this.fileNameFix = fileNameFix; } // my code for (FormDataBodyPart file : files) { boolean childSuccess = saveFile(file, path, channel); if (!childSuccess) { success = false; return success; } } private boolean saveFile(FormDataBodyPart file, String path, ChannelSftp sftpChannel) { InputStream is = file.getValueAs(InputStream.class); String fileName = file.getFormDataContentDisposition().getFileName(); . . . return boolean; }

          People

          • Assignee:
            Martin Matula
            Reporter:
            skelvin
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: