Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jitendra Rajput
Convert image to Base64
January 12, 2012 2:50 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

Is that any Liferay class available to convert image into Base64 data format ?
MICHAIL MOUDATSOS
RE: Convert image to Base64
January 12, 2012 3:09 AM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 110

Join Date: October 4, 2011

Recent Posts

If you can access the image from code you can do it easily yourself. Use ImageIO class (ImageIO.read()) to convert the image to a byte array (using the BufferedImage produced and ByteArrayOutputStream along with ImageIO.write() ). Then convert the byte array to a base64-encoded array using org.apache.commons.codec.binary.Base64.encodeBase64()

Liferay also has a Base64 utility, which you can use: com.liferay.portal.kernel.util.Base64

hope I helped...
Jitendra Rajput
RE: Convert image to Base64
January 12, 2012 5:36 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

thanks..will try as you suggested..!!
Jitendra Rajput
RE: Convert image to Base64
January 23, 2012 1:45 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

Here is the sample code..

1
2
3FileInputStream fileInputStream = new FileInputStream(filePath);
4 String  base64Format = new String(Base64.encodeBase64(IOUtils.toByteArray(fileInputStream)));
Abigail Klinton
RE: Convert image to Base64
October 21, 2013 8:07 PM
Answer

Abigail Klinton

Rank: New Member

Posts: 2

Join Date: September 24, 2013

Recent Posts

HI there
I am not the user of Liferay for now.Because i am new here.But i'd like to have a try.I usually convert the image using this image converting program before.But it can not convert image into Base64 data format .So if liferay can do that,i'd like to have a try.