commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gryllen <gryl...@gryllen.com>
Subject Commons-fileupload - Error in the documentiation
Date Wed, 02 Jul 2003 14:00:54 GMT
Hi!

In the documentation there is a example code snippet (see bellow) with 
a error in it.

//Normal usage example
public void doPost(HttpServletRequest req, HttpServletResponse res)
     {
         DiskFileUpload fu = new DiskFileUpload();
         // maximum size before a FileUploadException will be thrown
         fu.setSizeMax(1000000);
         // maximum size that will be stored in memory
         fu.setSizeThreshold(4096);
         // the location for saving data that is larger than 
getSizeThreshold()
         fu.setRepositoryPath("/tmp");

         List fileItems = fu.parseRequest(req);
         // assume we know there are two files. The first file is a small
         // text file, the second is unknown and is written to a file on
         // the server
         Iterator i = fileItems.iterator();
         String comment = ((FileItem)i.next()).getString();
         FileItem fi = (FileItem)i.next();
         // filename on the client
         String fileName = fi.getName();
         // save comment and filename to database
         ...
         // write the file
         fi.write("/www/uploads/" + fileName);
     }

// End of example

FileItem.write() do not take a string as a argument, it requires a 
java.io.File.
The following code will solve this problem.

		File fil = new File("/www/uploads/" + fileName);
		fi.write(fil);
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message