0

I have an image uploaded to a server with location like : opt/glassfish/domains/domain1/applications/j2ee-modules/SmartbadgePortal/images/2badge.jpg

I am trying to read the contents of the image rather than the image information. I searched a lot and could get the following solution for it :

                   File uploadedFile = new File(path);
                    System.out.println("Uploaded File is ***  : " + uploadedFile);
                    item.write(uploadedFile);
                    Image image = null;
                    image = ImageIO.read(uploadedFile);
                    System.out.println("Image Contents is ***  : " + image);

However, the when I used System.out to print "image". I get :

Image Contents is * : BufferedImage@10d7a81: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@722270 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 418 height = 387 #numDataElements 3 dataOff[0] = 2|#]

But , this is not what I need. I need the contents of the image and need to store it in a BLOB column in MySQL. Please help as I am been trying various methods like ByteArrayInputStream ,but every time I see only this info rather than image itself.

  • If you are trying to do this with Java, you could look at this link - http://www.roseindia.net/jdbc/save_image.shtml – Brian Hoover Jan 29 '12 at 23:28
  • How can you see the image on the standard output console? The info that you see is a string which is produced by the `toString()` method of the `Image` class you are using. You should look into some tutorials available on the internet before you start a question here. You attempts are far away from what you actually want to accomplish – Satadru Biswas Jan 29 '12 at 23:35

1 Answers1

0

Although it's not the answer you're looking for, my recommendation is to store the image in your server's file system and saving the file name (and maybe directory) in your DB. Storing an image in a BLOB cell is usually not a good idea unless there's a specific reason.

inhan
  • 7,394
  • 2
  • 24
  • 35