Sending an Image to a Java RestService

1
I am sending an image to a Java RestService. The only way that I could see to send it was to call the StringUtils.stringFromFile in the CommunityCommons and convert the binary into a string. When I get the image in the webservice, I tried using StringEscapeUtils.unescapeJava(data) to get the original String, but it does not match 100% with the sent image. First, am I approaching this in the correct way. Second, how can I convert the string back to the original image binary. I would appreciate any help that you can provide. Thanks, Steve
asked
2 answers
0

Hi Steve,

Please take a look at the RestServices module in the appstore. It has full support of sending binary data to rest services, for example by using the 'post' action.

Besides that, please not that a WebService != Restservice. Webservices use XML where binary data is base64 encoded, so instead of using unescape Java (which will just replace some quotes and slashed), you should use Base64DecodeToFile from community commons if you are publishing the webservice and want the xml string converted back to a file.

answered
0

To solve this problem, I stopped using the content directly and went back to grabbing the actual file document and using the community commons to encode it as a string.

I followed these steps:

  1. Grab the file document. (initially, I was grabbing the content.)
    1. CommunityCommons.Base64EncodeFile to convert the file document to a base 64 string.
  2. In the rest webservce, I call: Base64.decodeBase64(data.getBytes()) where data is the json string object passed from mendix
answered