0

ZK image validation

asked 2011-04-11 11:58:50 +0800

angelous gravatar image angelous
9 1

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.

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-04-13 21:00:31 +0800

PeterKuo gravatar image PeterKuo
481 2

You may manually check the length and width of the image.
If it's 0, throw exception.

I guess if a "qwerty.exe" renamed to "qwerty.jpg", the width would return 0.

link publish delete flag offensive edit

answered 2011-04-18 08:10:37 +0800

angelous gravatar image angelous
9 1

updated 2011-04-18 08:11:54 +0800

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.

link publish delete flag offensive edit

answered 2011-04-24 23:05:31 +0800

PeterKuo gravatar image PeterKuo
481 2

You should verify org.zkoss.image.Image,
not org.zkoss.zul.Image, a zk widget

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-04-11 11:58:50 +0800

Seen: 1,448 times

Last updated: Apr 24 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More