REST Services module: problem with parameter name for binary data in POST request

I would like to call an OCR API that expects a HTTP POST with the image to be processed in the request body . When sending the request with the REST client, everything works fine. With this tool, the request body looks as follows: -----------------------------2237299324779 Content-Disposition: form-data; name="file"; filename="20160617_143958.jpg" Content-Type: image/jpeg In Mendix, I am trying to send my request with the REST Services module, which can send binary data in the request body as described here. However, the OCR API does not respond to the request generated by Mendix properly. I suspect that the problem is with the parameter name (i.e. form field name) in the request body: while the API expects the binary data to be in a parameter named "file", the REST Services module probably puts the binary data of the image in a parameter named "Content" (i.e. the name of the attribute with the binary data in the Mendix object type System.Image). How can I solve this problem? Is there any way to adjust the parameter name the Rest Services module is using for binary data?
2 answers

In the source code of the Rest Services module, I found a comment that gave a solution to the problem. This comment in the method RestConsumer::buildMultiPartEntity says:

// .. or one of its children could be a filedocument. This way multiple
// file parts, or specifically named file parts can be send

Instead of making the main request entity a subclass of System.Image, I had to create a second entity that is a subclass of System.Image and creating an association between my main request entity and the second entity. The Rest Services module then takes the name of that association as the parameter/field name for the file binary data in the request body.


Using, I inspected the POST request generated by the REST Services module and found that the parameter name (i.e. form field name) carrying the image data in the request body is the file name (e.g. "20160617_143958.jpg"), not "Content" as I originally suspected.

So the question is: how can I change the parameter name (form field name) in the request body to be "file" (as expected by the API) instead of the file name?