0

Possible Duplicate:
Decode Base64 data in Java

enter code hereI have an image in base64 String: data:image/png;base64,iVBORw0KGgoAAAANS.... i would like to convert this String back to an image and store it to the server. Does anyone have any examples of this done in java.

I am having an error : The type org.apache.tomcat.util.buf.CharChunk cannot be resolved. It is indirectly referenced from required .class files (on the second line);

This is my code i am not sure what i am doing incorrectly:

 String encodedString = citizens.getPhoto();
 byte[] ba = Base64.decode(encodedString);
 decodedString = new String(ba);
   try {
          byte[] imageByteArray = decoder.decodeBuffer(citizens.getPhoto());
     FileOutputStream imageOutFile = new FileOutputStream(
                            "/resources/photos/mypic.jpg");
     imageOutFile.write(imageByteArray);
     imageOutFile.close();
     logger.info("Image Successfully Manipulated!");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
Community
  • 1
  • 1
devdar
  • 5,564
  • 28
  • 100
  • 153
  • Which part are you asking about, the decoding or the storing? – Perception Feb 03 '13 at 14:35
  • @ Perception I have the data as a base64 string so i may need to decode it and then store. – devdar Feb 03 '13 at 14:39
  • Right, please see the link I included. It has several good answers describing how you would decode the base 64 string, after which you would save the byte data. – Perception Feb 03 '13 at 14:44

0 Answers0