samedi 21 février 2015

org.zkoss.zul.Image to byte array?

I'm struggling trying to save an image in postgresql database using a byte array.


The problem is, i'm trying to convert the image to byte array and when I save it gives me this error


ERROR: column "avatar" is of type bytea but expression is of type bigint


this is the code I'm using to convert the image



public static byte[] getBytes(Object obj){
byte[] data = null;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1);
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
oos.flush();
oos.close();
bos.close();
data = bos.toByteArray();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return data;
}


Any help will be appreciated :)


PS: Sorry for the bad english


Aucun commentaire:

Enregistrer un commentaire