Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 78791 invoked from network); 13 Dec 2007 22:06:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Dec 2007 22:06:49 -0000 Received: (qmail 52980 invoked by uid 500); 13 Dec 2007 22:06:34 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 52694 invoked by uid 500); 13 Dec 2007 22:06:33 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 52684 invoked by uid 99); 13 Dec 2007 22:06:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Dec 2007 14:06:33 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [62.179.121.50] (HELO viefep32-int.chello.at) (62.179.121.50) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Dec 2007 22:06:34 +0000 Received: from [192.168.1.101] (really [84.113.196.60]) by viefep32-int.chello.at (InterMail vM.7.08.02.02 201-2186-121-104-20070414) with ESMTP id <20071213220614.OFDV17442.viefep32-int.chello.at@[192.168.1.101]> for ; Thu, 13 Dec 2007 23:06:14 +0100 Subject: RE: get image dimensions before upload? From: simon To: Jakarta Commons Users List In-Reply-To: <003601c83db2$340ba2f0$4900a8c0@dwdomain.local> References: <818087.3556.qm@web57404.mail.re1.yahoo.com> <003601c83db2$340ba2f0$4900a8c0@dwdomain.local> Content-Type: text/plain; charset=utf-8 Date: Thu, 13 Dec 2007 23:06:14 +0100 Message-Id: <1197583574.6595.2.camel@simon-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org Hi Andres, Your example code does check before the data is written to disk on the server, but after the data is transferred over the network. But the question (as I understand it) was whether it is possible to check the dimensions *before* the file is transferred from the client machine to the server, ie whether it is possible to get the web-browser to do this check. And the answer (short of something like activex) is no. Hmm..well, I guess a signed applet could be used in the page instead of a normal file-upload control. That could then perform any desired checks. That's a pretty big job though, and as a user of this website I would not necessarily want to allow the applets to run on my machine with filesystem access rights... Regards, Simon On Thu, 2007-12-13 at 12:01 -0600, Andrés M. Luna wrote: > Hi, > > Is simple, in your code add > > boolean isMultipart = ServletFileUpload.isMultipartContent(request); > FileItemFactory factory = new DiskFileItemFactory(); > ServletFileUpload upload = new ServletFileUpload(factory); > List items=null; > int width = 0; > int height = 0; > items = upload.parseRequest(request); > Iterator iter = items.iterator(); > while (iter.hasNext()) { > FileItem item = (FileItem) iter.next(); > > //Validation code > Image imageDimens = new ImageIcon(item.get()).getImage(); > width = imageDimens.getWidth(null); > height = imageDimens.getHeight(null); > > if (width == 100 & height == 150) { > File uploadedFile = new File("image.gif"); > item.write(uploadedFile); > } > > You need add in the import statements > > import java.awt.Image; > import javax.swing.ImageIcon; > > > Regards, > > Andrés Martínez > > > -----Original Message----- > From: loredana loredana [mailto:loredana888888@yahoo.com] > Sent: Thursday, December 13, 2007 7:02 AM > To: user@commons.apache.org > Subject: get image dimensions before upload? > > Hi, i'm new to this list. I have a question. I have a page where a user can > upload a image on the server. The way I did it was pretty basic: > > boolean isMultipart = ServletFileUpload.isMultipartContent(request); > FileItemFactory factory = new DiskFileItemFactory(); > ServletFileUpload upload = new ServletFileUpload(factory); > List items=null; > items = upload.parseRequest(request); > Iterator iter = items.iterator(); > while (iter.hasNext()) { > FileItem item = (FileItem) iter.next(); > File uploadedFile = new File("image.gif"); > item.write(uploadedFile); > > I need to make sure that the image the user uploads is of height 150 and > width 100 ....I can probably do that by saving the uploaded file, check the > dimensions and delete it in case it's doesn't have the necesary size. But is > there a way to check this before the file is uploaded? 10x > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org