+ Start a Discussion
kminevkminev 

Convert Salesforce Attachment.Body to a file in java

All,

 

I have a java code which makes a call to salesforce retrieves object along with their attachments.

 

In java I need to be able to take the Base64 string from the Attachment (myObject.Attachment.Body) and convert it to a real file on my hard drive.

 

I am always running to encoding miss-match exceptions.

 

Any help will be tremendously appreciated.

 

Thank you.

sfdcfoxsfdcfox

Make sure you're using binary mode when writing the file or you may cause that exception. I'd wager you're using a text writer instead of a binary writer. Also, make sure you're converting to a byte[] array, not a string.

NikuNiku

Please check that the attachment type should not be as Blob . Because then you can not able to parse it.. :(