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:[EMAIL PROTECTED]
> Sent: Thursday, December 13, 2007 7:02 AM
> To: [email protected]
> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]