Image displaying issue.

Hi. I have an issue displaying an image.
I debugged it and I saw a strange thing: in save() action file size is 10172 bytes, but when I retrieve it from database(showImage() action) it's size is 20343. It's almost twice largest!
Maybe somebody can help me. Please, look at my code.
I have a domain class Image:
Code:
class Image {
    byte[] file;
    String name;
    String alt;
    String title;
    String contentType;
    static constraints = {
        name(nullable: false, blank: false)
        file(nullable: false, maxSize: 1024 * 1024 * 2)
        contentType(nullable: false, validator: {val, obj ->
            return allowedContentTypes.contains(val);
        })
    }
    static allowedContentTypes = ['image/png', 'image/jpeg', 'image/gif']
}

I save this image in ImageController in the following way:
Code:
    def save() {
        def image = new Image(params)
        def file = ((MultipartRequest)request).getFile('file')
        image.contentType = file.getContentType()
        image.file = file.getBytes()
        if (!image.save(flush: true)) {
            render(view: "create", model: [image: image])
            return
        }

	flash.message = message(code: 'default.created.message', args: [message(code: 'image.label', default: 'Image'), image.id])
        redirect(action: "edit", id: image.id)
    }

I have next action in controller to display an image:
HTML:
    def showImage() {
        def image = Image.get(params.id)
        response.contentType = image.contentType
        response.contentLength = image.file.size()
        OutputStream out = response.getOutputStream();
        out.write(image.file);
        out.close();
    }
And finally I retrieve an image from my GSP like this:
Code:
<img src="${createLink(controller: 'image', action: 'showImage', id: image.id)}"/></g:link>
 
I found the reason! It's my database! I'm using postgresql 8.4 and I have next line in my BuildConfig.groovy:
Code:
runtime 'postgresql:postgresql:8.3-603.jdbc4'
When I changed to H2 database everything become ok and images display well.
Can anybody say how to fix it ? Cause I really need postgresql.
 
Top