REST Consume Response with corrupt binary image

Hello Mendix Community! I have done many REST consumptions via Mendix before and and having issues with one that I am currently working on.   I am consuming a REST service where a qr code is returned as the response to my request as a binary file.  My issue is that something is happening to the file on its way back to my app that is making it an invalid/corrupted image binary.   I have made the exact REST call on Postman and received a valid image file(have tried both JPG and PNG) that displays properly. However I intake the response directly to an image filedocument in the rest action in my microflow and the file displays as broken when brought onto a page.   I have downloaded the file from the filedocument that is created and compared the binary to the one received in Postman and it looks like the characters of the mendix file have been replaced by unknown character symbols.  I tried receiving the response as a string and converting to filedocument with same result. I realize that the response is being filtered/corrupted at some point but can’t figure out where/how to remedy.  Once the characters are replaced with unknown characters there is no way get back to a valid file. Any help would be appreciated!
2 answers

This turned out to be an interesting issue…


I had loglevels for REST Consume set to trace the entire time I was testing this rest call.  Ended up closing my modeler and then opening it again the next day and the call worked!

Determined to figure out what had been causing my issue, I set loglevels for REST Consume back to trace. All of a sudden, the Rest response images start coming in corrupted again. 

Turns out it was the Trace itself that was corrupting the contents of the incoming Binary file!  Definitely makes me appreciate why base64 encoded images are standard for REST services



Could you check in Console with “REST Consume” log level set up as Trace what you are receiving from your endpoint? There is a slight chance that Postman is adding some header value which Mendix does not (I had something similar in my project, had to stop and start local app after changes as Rerun locally didn’t reflected all changes what I made to REST call)

If response is exactly same then you may check what returns ‘StringFromFile’ from CommunityCommons (if you are sending/receiving file)

It is worth to check how it works on your computer and after deployment – database encoding may play a role there