Exibir imagem na gsp[Resolvido]
03/03/2010 00:00
def show = {
def somethingInstance = Something.get(params.id)
if (!somethingInstance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code:'something.label', default: 'Something'), params.id])}"
redirect(action: "list")
}
else {
[somethingInstance: somethingInstance]
byte[] image = somethingInstance.image
response.contentType = somethingInstance.ext
response.outputStream << image
response.outputStream.flush()
}
}
<img width="50" height="50"
src="${createLink(controller:'something', action:'image', id: something.id)}"/>
def save = {
def somethingInstance = new Something(params)
def foto2 = request.getFile('image')
somethingInstance.ext = foto2.contentType
if (somethingInstance.save(flush: true)) {
flash.message = "${message(code: 'default.created.message', args: [message(code: 'something.label', default: 'Something'), somethingInstance.id])}"
redirect(action: "show", id: somethingInstance.id)
}
else {
render(view: "create", model: [somethingInstance: somethingInstance])
}
}
def image= {
def something = Something.get(params.id)
byte[] image = something.image
response.contentType = something.ext
response.outputStream << image
}
<img width="100" height="100"
src="${createLink(action:'image', id: somethingInstance?.id)}"/></td>
Para se registrar, clique aqui.