Embedding an image that resides on the Mendix server in a regular web page

1
This afternoon I have tried if it is possible to embed an image that I have uploaded in a Mendix application into a regular web page that resides on a different server. I got a clue via this forum post that mentions the possibility of using a URL like this: http://localhost//file?fileID=123456 Unfortunately the URL only works when a user is logged in in Mendix in one of the browser tabs of the browser he/she uses. I suspected that the URL would work if Anonymous has read privileges for the entity that I use to store the uploaded image, but it looks like this is not the case. Or am I doing something wrong maybe? Update 5 Feb 2014: I tried the suggestion below using a deeplink and a download action at the end of the microflow to return the image. When I call the deeplink directly, it shows the image in a popup window. But when I include the deeplink in an < img src="" > tag, it still does not work. Any help or advice is appreciated.
asked
3 answers
1

Thanks you Bas van den Broek for pointing me into the right direction to solve this challenge. I have managed to create a custom request handler by using this blog post on the Mendix blog and by peeking into the java source code of the DeepLink module and the Creative Commons String utils.

answered
1

I did the following to get this to work for images:

  • Follow the steps from the blog [here] as was already mentioned in this post

  • Get rid of the 'toJSONString(..)'' method as we don't need it for images

  • Ensure that the object you retrieve inherits from the FileDocument entity, i retrieve it by FileID

  • Replace the code that creates the streams by the following:

        response.setContentType("image/jpg");
        OutputStream outputStream = response.getOutputStream();
        InputStream answerStream = Core.getFileDocumentContent(systemContext, ourObject);
        IOUtils.copy(answerStream, outputStream);
        IOUtils.closeQuietly(outputStream);
    
  • Register your Requesthandler URL also in your cloud environment configuration (separate tab for that) so that is also works in the cloud

answered
0

Theo - check out the DeepLink module in the appstore. With deeplink, you should be able to build a microflow that retrieves and downloads an image.

Mike

answered