Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6630

FileUpload.writeToTempFile() fails with commons-fileupload 1.4

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 8.2.0, 8.3.0
    • 8.3.0, 9.0.0-M1, 7.12.0
    • wicket-core
    • None

    Description

      FileUpload.writeToTempFile() fails with commons-fileupload 1.4

      As of commons-fileupload 1.4, writing the uploaded file to a temp file with fileUpload.writeToTempFile() fails with the following exception:

      org.apache.commons.io.FileExistsException: Destination '/var/folders/4y/_1z4yp3d7jv553km1yqc5v2r0000gn/T/null_15476330054763883202739767876103field' already exists
      at org.apache.commons.io.FileUtils.moveFile(FileUtils.java:2986)
      at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:405)
      at org.apache.wicket.markup.html.form.upload.FileUload.wripteTo(FileUpload.java:234)
      at org.apache.wicket.markup.html.form.upload.FileUpload.writeToTempFile(FileUpload.java:254)
      

      This only happens when the file is larger than the size threshold of 10 kB (by default). In that case the uploaded content is already in a temp file and will be moved to the newly created temp file. Commons-fileupload 1.3.3 used File.rename() for this; in 1.4 the implementation has been changed to FileUtils.moveFile(), which does not allow the destination to be present.

      To be functionally compatible with the old situation, FileUload.writeTo() should delete the provided file, if present, before writing.

      See the provided test case.

      Attachments

        1. uploadtest-8.3-SNAPSHOT.zip
          10 kB
          Laurens Hop
        2. uploadtest.zip
          10 kB
          Laurens Hop

        Activity

          People

            mgrigorov Martin Tzvetanov Grigorov
            laurenshop Laurens Hop
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: