Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top