Sending Image File to Browser [Grails]
My app have jpg image files that are displayed on my website.
in my GSP I do:
<img class="itemThumImage border-radius-top-3px"
src="${createLink(controller:'item', action:'getImage', id:item.id)}" />
my getImage action of my ItemConroller is:
def getImage() {
def item = Item.get(params.id)
def file = new
File(grailsApplication.parentContext.servletContext.getRealPath(item.id))
response.setContentType("image/jpeg")
response.setHeader("Content-disposition", "filename=\"${item.id}.jpg\"")
response.setContentLength(fileBytes.size())
response.outputStream << file.readBytes()
response.outputStream.close()
}
Is this a good way of sending the image back to the browser? I think that
the image is loaded into heap. Can I accelerate this process somehow? Do I
need close() at the last line or is it flush() or both?
No comments:
Post a Comment