• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Decoding Base64-encoded GIF

 
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 ]
 
Marshal
Posts: 25798
69
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic