How to convert string representation of file to binary from web service

Hello, I am using a web service that returns a file as a string. When I try to copy this to my entity in the XML-Domain mapping I get an error 'unable to convert string to binary...' I get this, however I wonder how I can handle this situation. I'm guessing I will need to use some custom Java code. Any thoughts? Thanks!!
2 answers

Is this string a 64baseEncodedString? If that's so you can map this string into the Content attribute of your File entity in your xml-to-domain mapping. The mapping will convert this file automatically.

Edit after comment:

Andrew, my mistake. You can map only a binary to the Contents attribute. So that wouldn't work for you. But you can do it slightly different. Save the returned string in a string attribute. Then you can use a java-action to decode the Base64encoded string into a system.image generalised object.

Basically you need to add a string attribute to your image entity. This entity have to be a generalisation of the system.image entity. After you're mapping you have the convert the string into a binary with the Base64 decode java-action.

You could look at for a java-action to decode to string. Or maybe some nice guy on this forum can help you out with a java-action.


If the file is send as a base64 string you can map it to a string attribute in a non-pers object:

After the call, create an instance of a entity (that is a FileDocument) and use the Java function: Base64DecodeToFile to put the string from ReportNP into the binary content attribute of TestFile.