• Post Reply Bookmark Topic Watch Topic
  • New Topic

Urgent: Need to know the size of Image Uploaded  RSS feed

Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I have an application where i upload a image through a web page to the server and put it in the database, i need to check that the image is of particualr height and width only and then only insert in the DB else show error. I tried it by converting the bytes as below but got -1 as height and width.
This coding is in the servlet class:
// f is the file object uploaded.
byte [] b=new byte[(int)f.length()];
System.out.println("after file read");
// this is the code to check the file length
Toolkit toolKit=Toolkit.getDefaultToolkit();
Image image=toolKit.createImage(b);
int width=image.getWidth(null);
int heigth=image.getHeight(null);
System.out.println("Height is "+heigth+" Width is "+width);
I get both as -1
I will be very thankful if anyone can help me out in this.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!