Forums de discussion

Exporting images from Liferay database

Heimo Laukkanen, modifié il y a 13 années.

Exporting images from Liferay database

New Member Publications: 20 Date d'inscription: 06/07/10 Publications récentes
Hi,

if any of you will have the need to export images straight from the Liferay database, here is a small tip for you.

Reading data from image table text_ column gives you access to the image data in Base64 encoding, but there is a catch!

Data is not just the image data, but it is actually serialized bytearray of the data written through objectoutputstream.

Took me some time to go through the code in Liferay and then take example from Base64.java and add following code to my content exporter, which uses Apache Commoncs Codec for Base64 decoding. Entry parameter is the string got from the database, return variable is the byte[] object Liferay wrote to the database, the actual data of the image.

public static Object stringToObject(String s) {
if (s == null) {
return null;
}

byte bytes[] = Base64.decodeBase64(s);

ByteArrayInputStream ubais = new ByteArrayInputStream(bytes);

try {
ObjectInputStream is = new ObjectInputStream(ubais);

return is.readObject();
} catch (Exception e) {
logger.info("Error " + e);
}

return null;
}

Have fun!
Roberto Barchino, modifié il y a 13 années.

RE: Exporting images from Liferay database

Junior Member Publications: 26 Date d'inscription: 11/01/11 Publications récentes
Thank you very much!!

The code works fine.