I have use the fileupload package and encountered error on this line in bold.
DiskFileItemFactory factory = new DiskFileItemFactory();
// maximum size that will be stored in memory
factory.setSizeThreshold(4096);
// the location for saving data that is larger than getSizeThreshold()
factory.setRepository(new File("/tmp"));
ServletFileUpload upload = new ServletFileUpload(factory);
// maximum size before a FileUploadException will be thrown
upload.setSizeMax(1000000);
List fileItems = upload.parseRequest(request);
// 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(new File("/www/uploads/", fileName));
Error catch:
org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. \tmp\upload_144f6414_11f26db7ce1__7ff8_00000000.tmp (The system cannot find the path specified)Processing of multipart/form-data request failed. \tmp\upload_144f6414_11f26db7ce1__7ff8_00000000.tmp (The system cannot find the path specified)
01-30-2009, 02:23 PM
Hack
Have you verified that the path specfied does, in fact, exist?
01-31-2009, 01:39 AM
abcat
I tried to put C:/ also cannot.
fi.write(new File("C:/", fileName));
02-03-2009, 02:07 AM
rajiv.jain
Hi abcat,
you are using i.next() twice, it is creating problem to you.
You have only item in iterator. whenever Iterator.next() method encountered, it will return the element and also pointer will start pointing to next element. Please use some refrence variable and use that instead of using i.next(). Or if you want to traverse please put a check on i.next().