S
sah_forum
Guest
I want to save and show an image into blob field in oracle 10g using grails. If i use Long raw field in database then it works. But in case of blob field it saves but doesn't show in the view page.
Here is the code:
Here is the code:
Code:
//Domain
class Hotel{
byte [] pic_
static mapping={}
static constraints = {}
}
//Controller
Class contrl
{
def save() {
def hotelInstance = new Hotel(params)
if (!hotelInstance.save(flush: true)) {
render(view: "create", model: [hotelInstance: hotelInstance])
return
}
flash.message = message(code: 'default.created.message', args: [message(code: 'hotel.label', default: 'Hotel'), hotelInstance.id])
redirect(action: "show", id: hotelInstance.id)
}
}
def displayLogo () {
def sponsor = Hotel.get(params.id)
response.contentType = "image/jpg"
response.contentLength = sponsor?.pic_.length
response.outputStream.write(sponsor?.pic_)
response.outputStream.flush()
}
//View
<td><img src="${createLink(action:'displayLogo ', id:hotelInstance?.id)}" height="42" width="42" /> </td>