Hi, the DefaultFileItem in commons-fileupload has handling for a problematic situation where calling renameTo() on the uploaded file fails although it is entirely possible to move the file manually.
The FileItem in t2 lacks this code. The attached patch adds the mentioned code to t2's FileItem (So this is really a copy/paste/compile/see-if-it-works as a patch for your convenience if you want to include it in t2 for those who haven't switched to decoupled fulcrum). Cheers, Ben -- Benjamin Peter +49-69-96244395 Application Engineer Moerfelder Landstr. 55 (zentropy:partners) 60598 Frankfurt, Germany
Index: src/java/org/apache/turbine/util/upload/FileItem.java =================================================================== RCS file: /home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/util/upload/FileItem.java,v retrieving revision 1.3 diff -u -r1.3 FileItem.java --- src/java/org/apache/turbine/util/upload/FileItem.java 23 Aug 2001 19:46:37 -0000 1.3 +++ src/java/org/apache/turbine/util/upload/FileItem.java 13 Apr 2002 02:12:03 +-0000 @@ -54,6 +54,8 @@ * <http://www.apache.org/>. */ +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -430,9 +432,40 @@ */ if (storeLocation.renameTo(new File(file)) == false) { - throw new Exception( - "Cannot write uploaded file to disk!"); - } + BufferedInputStream in = null; + BufferedOutputStream out = null; + try + { + in = new BufferedInputStream + ( new FileInputStream(storeLocation)); + out = new BufferedOutputStream(new FileOutputStream(file)); + byte[] bytes = new byte[2048]; + int s = 0; + while ( (s = in.read(bytes)) != -1 ) + { + out.write(bytes,0,s); + } + } + finally + { + try + { + in.close(); + } + catch (Exception e) + { + // ignore + } + try + { + out.close(); + } + catch (Exception e) + { + // ignore + } + } + } } else {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
