0

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:

        //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>
1
  • This program works fine in MySql database(LongBlob field) without any changes. But not working in oracle Commented Mar 10, 2013 at 5:48

1 Answer 1

1

Use a blob. Also your mime type is wrong

Hotel hotel = Hotel.get(params.id)
response.contentType = 'image/jpeg'
response.outputStream << hotel.pic_
response.outputStream.flush()

I also see there is a space after your action name in the createLink. I doubt that it is breaking anything, but get rid of it.

Sign up to request clarification or add additional context in comments.

1 Comment

still problem. why this code works in case of LongRaw?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.