I'm receiving a base64 string representation of GIF in SOAP response from a web service. I'm then trying to decode the string, using the org.apache.axis.encode.Base64 (I've also tried the Base64 class in Apache Commons Codec), and write it to a file to save the GIF, but the image is coming out garbled. My code is included below; can anyone see what I'm doing wrong?
[ December 05, 2008: Message edited by: Kamala Miller ] [ December 05, 2008: Message edited by: Kamala Miller ]
What are you doing wrong? You are taking the bytes which you carefully produced by decoding the Base64 string, and mangling them by making them into a String. Strings are for text. Images are not text. So just skip that step and write the byte array directly to the output file. Using a FileOutputStream. (You can do that with one line of code, too. You don't need a loop.)