Hi Paul,
hmmm, ok that makes sense...however, there's nothing in the fileitems list
either...here's my full code listing which i should have posted
earlier...pardon me for being so vague...
DiskFileItemFactory
diskFactory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload =
new ServletFileUpload(diskFactory);
servletFileUpload.setSizeMax(250000);
diskFactory.setSizeThreshold(4096);
String dirName = "\\";
File f = new File(dirName);
diskFactory.setRepository(f);
List fileItems = null;
try {
fileItems =
servletFileUpload.parseRequest(pageContext.getRequest());
}catch (FileUploadException e) {
System.out.println("no file
items"+ e);
}
String optionalFileName =
"";
FileItem fileItem = null;
Iterator i = fileItems.iterator();
while (i.hasNext()){
FileItem fileItemTemp =
(FileItem)i.next();
if (fileItemTemp.isFormField()) {
fileItemTemp.getFieldName();
fileItemTemp.getString();
if
(fileItemTemp.getFieldName().equals("writing header " +
"name"))
optionalFileName =
fileItemTemp.getString();
}
else
fileItem = fileItemTemp;
}
if (fileItem != null) {
String fName = fileItem.getName();
/* Save the uploaded file if its
size is greater than 0. */
if (fileItem.getSize() > 0) {
if
(optionalFileName.trim().equals(""))
fName =
FilenameUtils.getName(fName);
else
fName = optionalFileName;
String fullPath = dirName +
fName;
File saveTo = new File(fullPath);
try {
fileItem.write(saveTo);
}catch (Exception e){
System.out.println("An
error occurred when we tried to save the uploaded file."+e);
}
}
}
can you see anything that would cause it to throw an exception everytime except
when the post comes from a form in an html page?
thanks
b
----- Original Message ----
From: Paul J DeCoursey <[EMAIL PROTECTED]>
To: Jakarta Commons Users List <[email protected]>
Sent: Thursday, January 25, 2007 12:15:23 PM
Subject: Re: adding patch to jar
badi malik wrote:
>> How are you handling the request? I don't think the request object will have
>> a parameter named filedata.
>>
>
> like thus...
>
> fileItems =
> servletFileUpload.parseRequest(pageContext.getRequest());
>
> i'm using the pageContext to get the request in this sample because i pulled
> my code out of the servlet i was using originally just to see if that was
> part of the problem and put it in a scriplet...either way, there are no
> parameters in the request...i used the Enumeration object to verify this...
>
There will be no parameters on the request object because it does not
find any in a multipart request. You need to iterate over the fileItems
list to find your files.
Example:
// Process the uploaded items
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
processFormField(item);
} else {
processUploadedFile(item);
}
}
Hope this helps.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]