0

I am using image-gallery plugin for my grails application. It is saving small images like size less than 2kb. but when i try to save large image, it does not save.even greater 4kb image does not save. and showing exception as below:

Class
    java.sql.BatchUpdateException
Message
    ORA-24816: Expanded non LONG bind data supplied after actual LONG or LOB column 

Below is my domain. which i have modified from image-gallery plugin:

package org.grails.plugins.imagegallery

import javax.swing.ImageIcon
import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH

/**
 * Image holds the image bytes, its thumbnail and other properties related to an Image.
 * Image data field is required. Height, Width and thumbnail are created updating or creating an image.    
 */
class Image {
    byte[] thumbnail
    String caption
    String description
    byte[] data
    Integer width
    Integer height

    static mapping = {
        version(false)
        caption column: 'caption'
        description column: 'description'
        width column: 'width'
        height column: 'height'
        data column:'data',type:org.hibernate.type.MaterializedBlobType
        thumbnail column: 'thumbnail'
    }
    static constraints = {
        description(nullable: true)
        thumbnail(nullable: true)
        caption(nullable: true)
        data(maxSize:1073741824)
        width(nullable: true)
        height(nullable: true)
    }

    def beforeInsert = {
        java.awt.Image img = new ImageIcon(this?.data).getImage();
        this?.height = img.getHeight(null);
        this?.width = img.getWidth(null);
        loadThumbnail()
    }
    def beforeUpdate = {
        loadThumbnail()
    }



      /**
        * Creates the thumbnail. Takes maxWidth and maxHeight from config.groovy if provided
        *  otherwise cosiders the default max width & height as 170 & 120 respectively.
        */
        public void loadThumbnail() {
            if (this.data) {
                def imageUtil = new ImageUtil()
                imageUtil.load(data)
                float maxWidth = CH?.config?.grails?.imageGallery?.thumbnail?.maxWidth?:170
                float maxHeight = CH?.config?.grails?.imageGallery?.thumbnail?.maxWidth?:120
                imageUtil.thumbnailSpecial(maxWidth, maxHeight, 1,1)
                this.thumbnail = imageUtil.getBytes("JPEG")
            }
        }
    }

Any help would be appreciated.

Thanks.

8
  • Hi Rashedul.Rubel. Where do you try to save your image ?
    – Abincepto
    Sep 22, 2014 at 16:25
  • As it is by image-galllery plugin.And this plugin tries to save image as byte[] in database table. i am using oracle as my database. Sep 22, 2014 at 16:53
  • Do you have a constraint on your property ? If I suppose that photo is your property in your domain (ex: byte[] photo), did you add a constraint like : photo(nullable:true, maxSize: 1024 * 1024 * 2) ? (the maxSize of your array will be 2 Mo)
    – Abincepto
    Sep 22, 2014 at 17:10
  • yes tried with photo(nullable:false, maxSize: 1024 * 1024 * 20). i also tried with photo(nullable:false, maxSize: 1000000)// almost 1 GB. i also added mapping and given type:blob. but all were ended in vain. Sep 22, 2014 at 17:19
  • Ok, could you try to use this mapping: static mapping = { photo(type:org.hibernate.type.MaterializedBlobType) } ?
    – Abincepto
    Sep 22, 2014 at 17:32

0

Your Answer

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

Browse other questions tagged or ask your own question.