Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 66591 invoked from network); 30 Oct 2008 02:36:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Oct 2008 02:36:39 -0000 Received: (qmail 13397 invoked by uid 500); 30 Oct 2008 02:36:40 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 13341 invoked by uid 500); 30 Oct 2008 02:36:40 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 13330 invoked by uid 99); 30 Oct 2008 02:36:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2008 19:36:39 -0700 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Oct 2008 02:35:24 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1KvNOD-0005Bm-T3 for user@commons.apache.org; Wed, 29 Oct 2008 19:36:03 -0700 Message-ID: <20239931.post@talk.nabble.com> Date: Wed, 29 Oct 2008 19:36:01 -0700 (PDT) From: sim123 To: user@commons.apache.org Subject: Re: File Upload and request parameters In-Reply-To: <20238511.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: sim3159@gmail.com References: <20238511.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org Thank you very much for quick reply Martin, it worked, I appreciate your help. sim123 wrote: > > Hello, > > I am using FileUpload for multipart request handling, my request > contains three different parameter and one file, I want to read those > parameters first and then read the file as those paramters construct > directory where this file needs to be stored, here is the code > > protected void doPost(HttpServletRequest request, HttpServletResponse > response) throws ServletException { > int dir1 = 0 ; > int dir2 = 0 ; > int dir3 = 0; > String uploadLocation = null; > String fileName = null; > // parse request > if(ServletFileUpload.isMultipartContent(request)){ > ServletFileUpload upload = new ServletFileUpload(); > try { > FileItemIterator iterator = > upload.getItemIterator(request); > while(iterator.hasNext()){ > FileItemStream item = > iterator.next(); > String name = item.getFieldName(); > InputStream stream = > item.openStream(); > if(item.isFormField()){ > if("dir1".equals(name)){ > dir1 = > Integer.parseInt(Streams.asString(stream)); > }else > if("dir2".equals(name)){ > dir2 = > Integer.parseInt(Streams.asString(stream)); > }else > if("dir3".equals(name)){ > dir3 = > Integer.parseInt(Streams.asString(stream)); > } > uploadLocation = > server_url+File.separatorChar+tenantId+File.separatorChar+collectionId+File.separatorChar+rowId > ; > new File(uploadLocation).mkdirs(); > }else { > > System.out.println("File field" + name + "with file name" + > item.getName()); > fileName = > item.getName(); > //perform file > storing operations > > File uploadedFile = new > File(uploadLocation+File.separatorChar+fileName); > > FileOutputStream outputstream = new > FileOutputStream(uploadedFile); > long number = Streams.copy(testStream, > outputstream, true); > System.out.println("result from > outpoutstream operation" + number); > } > > } > > > > } catch (FileUploadException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch(NumberFormatException e){ > e.printStackTrace(); > } > } > > } > > > however for some reason FileItem is being read first so I can not > store this file at desired location it is (/usr/sim/0/0/0/filename), > can some one please suggest how can I make sure that I read form item > first then file items. > > I do appreciate all the help and time. Thanks > > -sim > -- View this message in context: http://www.nabble.com/File-Upload-and-request-parameters-tp20238511p20239931.html Sent from the Commons - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org