I'm trying to create a LitRenderer
for dynamically generated images that can be either gif/jpg/png files using a StreamResource
in Vaadin. I also have the byte[]
and so on but I figure using a StreamResource
is the better way to do this. That being said I'm not sure how to display the StreamResource
in the LitRenderer
code. Below is my code:
private Renderer<CustomImageData> createImageRenderer() {
return LitRenderer.<CustomImageData>of("""
<vaadin-horizontal-layout>
<div><img src=\"${item.imageStreamResource}\"/></div>
</vaadin-horizontal-layout>""")
.withProperty("imageStreamResource", CustomImageData::getThumbnailAsStreamResource);
}
Clearer I can't just pass the imageStreamResource
as a src
as it's not a URL. It manages URL's but it's not a URL. My CustomImageData
also has methods like getByteData()
, getMimeType()
, and so on but as mentioned above using a StreamResource
seems like the better implementation.
My question is how edit the code above so that it will display the image for <img>
? The only examples I can find including such as this one and this one only seem to show images that are pre-defined, nothing dynamically generated.
And in case this helps the calling code is:
grid.addColumn(createImageRenderer())
.setKey(THUMBNAIL)
.setHeader(THUMBNAIL);