groovydev / twitter-bootstrap-grails-plugin

Grails plugin for Twitter Bootstrap CSS framework resources
173 stars 92 forks source link

Image property in domain class #141

Open cihanzengin opened 7 years ago

cihanzengin commented 7 years ago

Hello, i tried to add img field on my domain class, i run my app everyting is ok. When i try to add img i get this error,

Property carImg is type-mismatched

here is my domain-class

package carrentco

class Car {

    String brand
    String model
    String fuelType
    BigDecimal pricePerDay
    byte[] carImg

    static constraints = {
        brand(inList:["AUDI", "BMW", "MERCEDES", "NISSAN", "HONDA", "FORD"])
        model()
        fuelType(inList:["FUEL", "DIESEL", "AUTOGAS"])
        pricePerDay(min:0.0, max:1000.0)
        carImg(nullable:true, maxSize:1000000)
    }

}

here is what i add to my controller.

def displayCarImg = {
        def car = Car.get(params.id)
        response.contentType = "image/jpeg"
        response.contentLength = car?.carImg.length
        response.outputStream.write(car?.carImg)
    }

and here is my show.gsp

<img src="${createLink(action:'displayCarImg', id:carInstance?.id)}" />