Search code examples
javaimagedynamicrestlet

Serve dynamic generated images using restlet


I have searched online for a while and almost all the questions regarding image serving using restlet are about static images. What I want to do is to serve dynamic generated image from restlet.

I have tried serving static images using restlet, it's working. Also, I can successfully generate a dynamic image and store them in a local folder, so the problem goes to how to serving it. If it's an http response, what I shall do is to attach all the bytes of the image to the body of the response. However, I am not sure about how to use restlet to do that? Is it FileRepresentation?

Newbie in this field, and any suggestion will be welcomed.

Thanks


Solution

  • FileRepresentation should work if you write the image to a file first. For a more efficient approach, you can create your own Representation class by extending OutputRepresentation and overriding the write(OutputStream) method.