Base64 decoding - How to decode to a file properly?
3
I've an image, a photo, base64 encoded. Showing the image is no problem with this._image.src = this._mxObject.get(this.pictureAttr); The base64 string is stored in an attribute in a Mendix object, string unlimited. I now try to decode the string and store in a Mendix FileDocument. By the way, I removed the text data:image/jpeg;base64, from the string, so it is the pure base64 encoded string from the image. I use CommunityCommons.Base64DecodeToFile to decode and store the image. Parameters are 1) the string attribute with the base64 encoded image and 2) an Image object, I want to store the image in. The file is stored ok, but is not an image. It cannot be opened with Paint for instance. Decoding exactly the same string with an online decoder http://www.motobit.com/util/base64-decoder-encoder.asp does result in an image file that can be opened with Paint. I did see that the file decoded by Mendix is almost twice as big as the file decoded with the online tool. Anybody that can help me here?
asked
Toon Verschoor
1 answers
8
Hi Toon,
I got problems with the same subject. Solved it with (snippet).
byte [] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(value.getBytes());
Core.storeFileDocumentContent(c, obj, new ByteArrayInputStream(decoded));