-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi.
I'm devoloping a zk application with a form having an upload button. When clicked, it opens a browser window with a default "save as" dialog and upon confirmation it show an image preview. I'm trying to constraint the uploaded files to accept only images. This is easy to accomplish when the validation is only according with the file extension using an if clause like this:
if(media instanceof org.zkoss.image.Image){ //do something }else{ Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR); }
So far so good, but here's my problem: If an invalid image is provided, this validation doesn't work. For instance a corrupted image (lenght zero) or renamed file: "qwerty.exe" to "querty.jpg". I've noticed that a warning is thrown, but i can't catch it with a try catch block.
Apr 11, 2011 5:40:50 PM org.zkoss.image.AImage init:126 WARNING: Unsupported image format: jpg; its width and height are assumed to zero
Is there any way to perform this validation? I'm using ZK 5.0.6.
Thanks in advance.
Thanks for your reply PeterKuo.
I tried to check both lenght, width and height of the object, but the results are not what i expected. Lenght returns a value different from zero. Width and Height always return the value specified in the image declaration. I'm declaring the image object in the zul file like this,
<image id="photo" width="100px" height="130px" mold=""></image>
The problem still remains.
Asked: 2011-04-11 11:58:50 +0800
Seen: 1,448 times
Last updated: Apr 24 '11