• Post Reply Bookmark Topic Watch Topic
  • New Topic

Decoding Base64-encoded GIF

 
Kamala Miller
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks,
Kamala



[ December 05, 2008: Message edited by: Kamala Miller ]
[ December 05, 2008: Message edited by: Kamala Miller ]
 
Paul Clapham
Sheriff
Posts: 21882
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Kamala Miller
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul - that fixed it!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!