Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 9537 invoked from network); 11 Jul 2003 19:34:51 -0000 Received: from mail.printtime.com (216.81.251.1) by daedalus.apache.org with SMTP; 11 Jul 2003 19:34:51 -0000 Received: from [65.26.167.205] (HELO printtime.com) by mail.printtime.com (Stalker SMTP Server 1.8b8) with ESMTP id S.0001953795 for ; Fri, 11 Jul 2003 14:37:38 -0500 Message-ID: <3F0F111E.3010408@printtime.com> Date: Fri, 11 Jul 2003 14:33:50 -0500 From: Brian Cook Organization: Print Time User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: fileUpload NullPointerException References: <1057925436.587.47.camel@phoenix> <3F0EEA8B.5050708@printtime.com> <3F0F032C.7030906@printtime.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N item.write(fileName) Is the method that will throw FileUploadException if no actual file is returned. i.e. A blank file input type FileUpload.parseRequest(request) Will throw Exceptions if it can not read the POST data, or write to disk. > "Jakarta Commons Users List" writes: > >>Daryl, >> >>I am guessing the instance you described with three file upload fields >>falls into one of the following >> >> o All three file input fields have the same name. Which would return >>only one file name. > > They are unique. I have another page with only one upload field. If you > put nothing in it is does not throw an exception. > >> >> o There is some scripting on the client side to account for it. > > You mean browser scripting? I assume that if you don't put anything in it, > the browser does not submit the field (that is, the browser doesn't try to > encode nothing for an upload). > >> o You have a test at some point in your code to skip the file upload if >>the form does not return a file name to the servlet. >> > > Here's my servlet code (in request wrapper) that parses the request: > > DiskFileUpload upload = new DiskFileUpload(); > * List items = upload.parseRequest(this, memoryLimit, fileSizeLimit, > savePath); > Iterator iter = items.iterator(); > while (iter.hasNext()) { > FileItem item = (FileItem) iter.next(); > if (item.isFormField()) { > String key = item.getFieldName(); > String value = item.getString(); > setParameter(key, value, false); > } else { > fileUploadItems.put(item.getFieldName(), item); // save to a HashMap > for later use > } > } > > What I seem to be hearing is that the line with the * is supposed to throw > an exception if you don't enter anything into the upload field. I don't > see how a developer could possibly make use of FileUpload if that were the > case - there would then be no means to use the rest of the parameters to > do something other than crash miserably. > > Is it a call to item.write() that would fail if nothing were uploaded? > >> o The servlet does not actually write the file to disk so the >>fileItem.write(fileName) method is not actually called. > > > That's true, I guess. There is no FileItem that makes it into my HashMap, > so I never call write on it. > > It seems to me that if you don't put anything in the file upload control > on the page, the browser doesn't send anything for it and FileUpload never > sees it in the request and everything works as if there was never a file > upload control on the page in the first place. > > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > mailto:daryl@6degrees.com > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-user-help@jakarta.apache.org > >