How to render an image easily in Grails



After Creating the grails application you should have to do these changes in your project :

Step 1: index.gsp-------

<td><img height="200" width="200" src="${createLink(action:'pic', id:profileInstance.id)}"/></td> 

Step 2: ProfileController------

def pic()
{
    response.setHeader 'Content-Type', 'image/jpg'
    response.outputStream.withStream {it << Profile.findById(params.id).photo}
}



[ Note :
I thought you have a domain (Profile) property for image as:
String name
String emailId
byte photo

]
Powered by Blogger.