I have a public facing application that is architected with multiple nsfs. I have one nsf that's public facing that manages data through Java controllers in the non-public facing nsfs. For security reasons the non-public nsfs do not allow URL browsing so I can't use the usual "/0/" + UNID + "/$FILE/" + PhotoFilename to display the image on the XPage.
In the controller I can get the attachment (EmbeddedObject) from the document, but I'm not sure how to get it to display in an <xp:image> or <xp:inputRichText> control.
I am using the OpenNTF api, but I can't see anything there that seems to help.
Thanks, Scott.
One solution: base64 encode the image and use the encoded string in an img tag. Here's a simple code example that uses the inputstream from the EmbeddedObject in a method in a Java controller:
public String getImageAsBase64(InputStream inputStream) {
return Base64.encodeBytes(IOUtils.toByteArray(inputStream));
}
You can then display the base64 encoded image (assuming your Java controller is called 'controller'):
<img src="data:image/jpeg;base64,#{javascript:controller.getImageAsBase64()}" />