Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 95245 invoked from network); 5 Oct 2004 04:07:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 5 Oct 2004 04:07:15 -0000 Received: (qmail 27193 invoked by uid 500); 5 Oct 2004 04:07:08 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 26979 invoked by uid 500); 5 Oct 2004 04:07:07 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 26966 invoked by uid 99); 5 Oct 2004 04:07:07 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of mfncooper@gmail.com designates 64.233.170.207 as permitted sender) Received: from [64.233.170.207] (HELO mproxy.gmail.com) (64.233.170.207) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 04 Oct 2004 21:07:06 -0700 Received: by mproxy.gmail.com with SMTP id v30so743522rnb for ; Mon, 04 Oct 2004 21:07:05 -0700 (PDT) Received: by 10.38.8.80 with SMTP id 80mr1912422rnh; Mon, 04 Oct 2004 21:07:04 -0700 (PDT) Received: by 10.38.179.21 with HTTP; Mon, 4 Oct 2004 21:07:04 -0700 (PDT) Message-ID: <16d6c6200410042107576b5aff@mail.gmail.com> Date: Mon, 4 Oct 2004 21:07:04 -0700 From: Martin Cooper Reply-To: Martin Cooper To: Jakarta Commons Users List Subject: Re: DiskFileUpload.parseRequest returns no items In-Reply-To: <41621CDE.70605@michaelmcgrady.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <16d6c620041004193873047704@mail.gmail.com> <41621CDE.70605@michaelmcgrady.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N On Mon, 04 Oct 2004 21:02:38 -0700, Michael McGrady wrote: > Hi, Martin, > > You are not saying, are you, Martin that you cannot use Struts and > "worry about how to use" commons classes yourself? Yes, I am. Unless you deliberately disable Struts' multipart handling, or you don't use an ActionForm, Struts will have already parsed the input stream before your Action is invoked, leaving nothing for your Action to parse. -- Martin Cooper > For example, as in: > > package com.crackwillow.app.load.upload; > > import java.io.IOException; > import java.util.Hashtable; > import java.util.Iterator; > import java.util.List; > import java.util.Vector; > > import javax.servlet.http.HttpServletRequest; > > import org.apache.commons.fileupload.DiskFileUpload; > import org.apache.commons.fileupload.FileItem; > import org.apache.commons.fileupload.FileUploadException; > > import com.crackwillow.app.load.upload.UploadFileItem; > import com.crackwillow.app.load.upload.UploadConstant; > import com.crackwillow.log.StdOut; > > public class UploadParser { > > public UploadParser() { > } > > public void parse(HttpServletRequest req, > Vector uploadListeners, > int fileSizeLimit, > Hashtable parameters, > Hashtable files, > String tmpFolder, > String encoding) > throws IOException { > DiskFileUpload dfu = new DiskFileUpload(); > dfu.setSizeMax(fileSizeLimit); > dfu.setSizeThreshold(UploadConstant.MEMORY_BUFFER_SIZE); > dfu.setRepositoryPath(tmpFolder); > if(encoding != null) { > dfu.setHeaderEncoding(encoding); > } > List list = null; > try { > list = dfu.parseRequest(req); > } catch(FileUploadException fue) { > throw new IOException(fue.getMessage()); > } > Object obj = null; > for(Iterator iter = list.iterator(); iter.hasNext();) { > FileItem fi = (FileItem)iter.next(); > String fieldName = fi.getFieldName(); > if(fi.isFormField()) { > String holder = null; > if(encoding != null) { > holder = fi.getString(encoding); > } else { > holder = fi.getString(); > } > Vector params = (Vector)parameters.get(fieldName); > if(params == null) { > params = new Vector(); > parameters.put(fieldName, params); > } > params.addElement(holder); > } else { > String fin = fi.getName(); > > if(fin != null) { > UploadFileItem ufi = new UploadFileItem(fi); > fin = fin.replace('\\', '/'); > int j = fin.lastIndexOf("/"); > if(j != -1) { > fin = fin.substring(j + 1, fin.length()); > } > ufi.setFileName(fin); > ufi.setContentType(fi.getContentType()); > ufi.setFileSize(fi.getSize()); > files.put(fieldName, ufi); > } > } > } > } > } > > where UploadFileItem is a simple FileItem wrapper, as in: > > package com.crackwillow.app.load.upload; > > import java.io.BufferedInputStream; > import java.io.InputStream; > import java.io.IOException; > import java.io.Serializable; > > import org.apache.commons.fileupload.FileItem; > > import com.crackwillow.log.StdOut; > > public class UploadFileItem > implements Serializable { > private FileItem fi; > private String contentType; > private String fileName; > private long fileSize; > > public UploadFileItem() { this.fi = null; } > public UploadFileItem(FileItem fi) { this.fi = fi; } > > public FileItem getFileItem() { return fi; } > public long getFileSize() { return fileSize; } > public String getFileName() { return fileName; } > public String getContentType() { return contentType; } > > public void setFileSize(long fileSize) { this.fileSize = > fileSize; } > public void setFileName(String fileName) { this.fileName = > fileName; } > public void setContentType(String contentType) { this.contentType > = contentType; } > > public InputStream getInputStream() { > if(fi == null) { > return null; > } > > InputStream is = null; > try { > is = new BufferedInputStream(fi.getInputStream()); > } catch (IOException ioe) { > StdOut.log("log.error",ioe.getMessage()); > } > return is; > } > > public byte[] getData() { > InputStream is = getInputStream(); > if(is != null) { > int i = (int)getFileSize(); > if(i > 0) { > byte data[] = new byte[i]; > try { > is.read(data); > is.close(); > } catch(IOException ioe) { } > return data; > } else { > return null; > } > } else { > return null; > } > } > > public void reset() { > if(fi != null) { > fi.delete(); > } > } > } > > Right? > > Michael McGrady > > > > > Martin Cooper wrote: > > >File upload is already supported by Struts, so you don't have to worry > >about how to use Commons FileUpload yourself. If you try to do so, the > >result you are seeing is to be expected, since Struts has already > >parsed the request, and it is no longer available for your code to > >also parse. > > > >For information on how to use the file upload capabilities in Struts, see: > > > >http://wiki.apache.org/struts/StrutsFileUpload > > > >-- > >Martin Cooper > > > > > >On Mon, 4 Oct 2004 10:04:16 -0400, Ivan Vasquez wrote: > > > > > >>I'm trying to use commons.fileupload from struts to avoid having > >>uploaded files be part of the session. > >> > >>Following the simplest example I attempt to parsePequest but it does not > >>return any items. I verified the request and it does contains what I'm > >>expecting. The form's enctype is multipart/form-data. I'm using the > >>current release, 1.0. > >> > >>Thanks in advance. > >>Ivan > >> > >>--------------------------------------------------------------------- > >>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > >>For additional commands, e-mail: commons-user-help@jakarta.apache.org > >> > >> > >> > >> > > > >--------------------------------------------------------------------- > > > >To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > >For additional commands, e-mail: commons-user-help@jakarta.apache.org > > > > > > > > > > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org