Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 23670 invoked from network); 10 Jul 2008 02:07:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Jul 2008 02:07:20 -0000 Received: (qmail 38437 invoked by uid 500); 10 Jul 2008 02:07:18 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 38351 invoked by uid 500); 10 Jul 2008 02:07:18 -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 38340 invoked by uid 99); 10 Jul 2008 02:07:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Jul 2008 19:07:17 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of arashbi@gmail.com designates 209.85.146.179 as permitted sender) Received: from [209.85.146.179] (HELO wa-out-1112.google.com) (209.85.146.179) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jul 2008 02:06:26 +0000 Received: by wa-out-1112.google.com with SMTP id m34so2085080wag.10 for ; Wed, 09 Jul 2008 19:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=bftwt0JATTQ8h53Z977ILf77DYVsE7Fh74etm//iAzo=; b=ClD1gN3+ULXZ8GAiuwoqc36Y9msp4PphDtorDUrxN5Q2q+u/XSa/L8OS8Cc4JHHjCN GYx6N+hr46YFDQqpP1Ii+JGF+HiPNgWvL/mtCxLX48jXRKawyFAGaHmiOxIT3vfE5g5W HSDPRrOLFBixz2tpaBl2gkg3gevepuGmeYbO8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=Yj0vKsNOAdH9p4V1ZegHr3JUBYE1Z9OehletCRa9ayKhs2ylqerjDWt2H+Httttnxu c5GHRgzJ07fRL765J02c6mfV53QuZHtwHitul8BfaKu0BFOx/Og5uhiLA9w8sn97x73Z e98MHfWxCMEjqJIPQCOZtIqzNsxh2SuRjyW6M= Received: by 10.114.154.1 with SMTP id b1mr10277449wae.4.1215655608505; Wed, 09 Jul 2008 19:06:48 -0700 (PDT) Received: by 10.114.169.11 with HTTP; Wed, 9 Jul 2008 19:06:48 -0700 (PDT) Message-ID: <2856b29d0807091906k612e15aat26dbece0a3da7150@mail.gmail.com> Date: Wed, 9 Jul 2008 22:06:48 -0400 From: "Arash Bizhan zadeh" To: "Commons Users List" Subject: Re: Stream ended unexpectedly In-Reply-To: <1ae8b19d0807091657k49a7239ew5066c1dbd4217c82@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11233_22519676.1215655608486" References: <1ae8b19d0807091657k49a7239ew5066c1dbd4217c82@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_11233_22519676.1215655608486 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline I was trying to implement a SAAJ solution lately and I faced the same error. The route cause in my case was because file was big and server was dropping the connection before reading the whole file. Problem solved by increasing the timeout. -arash On Wed, Jul 9, 2008 at 7:57 PM, Stelios Philippou wrote: > I have just found Apache fileUpload, to help me with the function :) > Anyway, after a lot of trial and error to try and make it work with out > it, i was unsuccessful. So i have tried fileUpload. > > Everything was ok, i have my working code : > > private void process(HttpServletRequest request, Picture myForm) > { > // Validate text. > boolean isMultipart = > ServletFileUpload.isMultipartContent(request); > System.out.println(isMultipart); > > ServletFileUpload upload = new ServletFileUpload(); > upload.setFileSizeMax(41943040); // 5 mb > // Parse the request > try { > FileItemIterator iter = upload.getItemIterator(request); > while (iter.hasNext()) { > FileItemStream item = iter.next(); > String name = item.getFieldName(); > InputStream stream = item.openStream(); > > if (item.isFormField()) { > System.out.println("Form field ");//+ name + " > with value " + Streams.asString(stream) + " detected."); > } else { > System.out.println("File field " + name + " with > file name " + item.getName() + " detected." + > item.getContentType().length()); > // Process the input stream > //... > // String imageId = > request.getParameter("uploadfile"); > String imageName = > request.getParameter("imageName"); > if (imageName == null) { > System.out.println("Null Picture Name"); > imageName = name; > } > System.out.println(item.getContentType()); > // Open the remote > Properties props = new Properties(); > props.put(Context.INITIAL_CONTEXT_FACTORY, > > "org.jnp.interfaces.NamingContextFactory"); > props.put(Context.PROVIDER_URL, > "localhost:1099"); > Context ctx = new InitialContext(props); > extraRemote exRemote = (extraRemote) > ctx.lookup("Project/extraBean/Remote"); > > > int fileSize = request.getContentLength(); > byte[] buffer = new byte[fileSize]; > int readBytes = -1; > System.out.println(request.getInputStream()); > > InputStream a = request.getInputStream(); > System.out.println(fileSize +" " + a); > a.read(); > System.out.println(buffer); > /*while ((readBytes = a.read(buffer, 0, > fileSize)) != -1) { > a.read(buffer, 0, readBytes); > }*/ > but when i try and run the while loop it will run always around 2 - 4 > lines and stop. Never more. > If i try and do the below it will read a lot more, if not all the image > > BufferedReader reader = new BufferedReader(new > InputStreamReader(request.getInputStream())); > String line = null; > line = reader.readLine(); > while ((line = reader.readLine()) != null) { > System.out.println(line); > } > > But still will bring me an error in the end > [STDOUT] -----------------------------7827094435720167761855652711 > [STDOUT] Content-Disposition: form-data; name="imageName" > [STDOUT] -----------------------------7827094435720167761855652711-- > [STDOUT] Stream ended unexpectedly > > > Can someone please let me know what i am doing wrong ? IS there > something missing ? SHould i try something else ? Should i change > something ? > Shouldnt this work the way it is ? > > Stelios > -- The dirtiest book of all is the expurgated book. ---- Walt Whitman ------=_Part_11233_22519676.1215655608486--