Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 78875 invoked from network); 6 Jul 2007 07:32:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Jul 2007 07:32:23 -0000 Received: (qmail 53775 invoked by uid 500); 6 Jul 2007 03:12:19 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 53729 invoked by uid 500); 6 Jul 2007 03:12:19 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: 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 53718 invoked by uid 99); 6 Jul 2007 03:12:19 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jul 2007 20:12:19 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of ben.kuek@abridge.com.au designates 202.154.92.226 as permitted sender) Received: from [202.154.92.226] (HELO smtp.per.people.net.au) (202.154.92.226) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jul 2007 20:12:13 -0700 Received: (qmail 30037 invoked from network); 6 Jul 2007 03:11:47 -0000 Received: from 218-214-164-106.people.net.au (HELO [172.16.0.129]) ([218.214.164.106]) (envelope-sender ) by smtp.per.people.net.au (qmail-ldap-1.03) with SMTP for ; 6 Jul 2007 03:11:47 -0000 Message-ID: <468DB305.9060905@abridge.com.au> Date: Fri, 06 Jul 2007 11:12:05 +0800 From: Ben Kuek User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: [FileUpload] Servlet stopping at servletFileUpload.parseRequest(request) References: <468C550B.7070201@abridge.com.au> <16d6c6200707051054x1e0ea52cu5eef9f841f3a9064@mail.gmail.com> In-Reply-To: <16d6c6200707051054x1e0ea52cu5eef9f841f3a9064@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Thank you for your reply, I'll be more descriptive; 1) I change the content to include blank lines and confirmed its arrival at the servlet. Printing the request stream at the servlet I get: Content-type: multipart/form-data, boundary=AaB03x --AaB03x content-disposition: form-data; name="field1" Joe Blow --AaB03x content-disposition: form-data; name="pics"; filename="file1.txt" Content-Type: text/plain ... contents of file1.txt ... --AaB03x-- 2) The part I commented are just code to print the request stream. I tested with and without printing the stream to the console. 3) On the servlet side, I have: public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload servletFileUpload = new ServletFileUpload(factory); try { // Print the request stream int intChar; BufferedReader testBR = request.getReader(); while( (intChar = testBR.read()) != -1) { System.out.print((char)intChar); } testBR.close(); // It doesn't get pass this line List items = servletFileUpload.parseRequest(request); Iterator iter = items.iterator(); // ..... code omitted } catch (Exception e) { // this part is not run System.out.println(e.getMessage()); e.printStackTrace(); log.error(e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } response.setStatus(HttpServletResponse.SC_OK); } else { // not multipart response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } Rgds, Ben Martin Cooper wrote: > A few comments: > > 1) The content you quote below does not match that in the RFC. The blank > lines are very important. > 2) Your code shows some stuff that's commented out that would prevent the > upload from working if it was not commented out. > 3) You don't show how you're creating and initialising the > servletFileUpload > instance, so we can't tell if you got that right. > > -- > Martin Cooper > > > On 7/4/07, Ben Kuek wrote: >> >> >> Hello, >> >> I am using commons-fileupload-1.2 >> >> I am trying to upload a multipart/form-data from a client application >> (written in C#) >> to the servlet. >> >> The servlet stops at: >> >> servletFileUpload.parseRequest(request); >> >> returning an internal server error (500) to the client. >> There are no error messages printed. >> System.out.println(exception.getMessage()); doesn't seem to do anything >> >> >> >> ------------------------------------------------------------------------------------------- >> >> >> For testing, I made sure that the client sent the following string >> (example from RFC 1867): >> >> Content-type: multipart/form-data, boundary=AaB03x >> --AaB03x >> content-disposition: form-data; name="field1" >> Joe Blow >> --AaB03x >> content-disposition: form-data; name="pics"; filename="file1.txt" >> Content-Type: text/plain >> ... contents of file1.txt ... >> --AaB03x-- >> >> >> >> ------------------------------------------------------------------------------------------- >> >> >> In the servlet, I made sure that the string is received by printing the >> request stream: >> >> //int intChar; >> //BufferedReader testBR = request.getReader(); >> //while( (intChar = testBR.read()) != -1) { >> // System.out.print((char)intChar); >> //} >> //testBR.close(); >> >> // I've confirmed that the string printed are as sent by >> the client >> >> // Servlet will not move pass this line >> List items = servletFileUpload.parseRequest(request); >> >> ------------------------------------------------------------------------------------------- >> >> >> >> Am I doing something wrong? >> >> Warmest regards, >> Ben >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org >> For additional commands, e-mail: commons-user-help@jakarta.apache.org >> >> > > ------------------------------------------------------------------------ > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.476 / Virus Database: 269.10.0/886 - Release Date: 4/07/2007 1:40 PM > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org