title: Class cast exception in Groovy
body: <p>I want to upload an image using a groovy on grails.
  My gsp page is as follows (I am showing a simplified version of the original)</p>
  
  <pre><code>&lt;g:form controller="post" action="save" enctype="multipart/form-data"&gt;        
        My picture  &lt;input type="file" name="myPicture" /&gt;     
      &lt;g:submitButton name="submit" value="Save"/&gt;
  &lt;/g:form&gt;
  </code></pre>
  
  <p>My domain class is as follows:</p>
  
  <pre><code>class Post {    
  
  byte[] myPicture
  
  static mapping = {
      myPicture type:  "blob" 
  }
  </code></pre>
  
  <p>I need this mapping otherwise MySql will create a smallblob which is to small to fit the images </p>
  
  <pre><code>static constraints = {
      myPicture(nullable:false)      
  }
  
  }
  </code></pre>
  
  <p>At the controller I have an action called save which is as follows:</p>
  
  <pre><code>def save = {                               
      def post = loadPost(params.id)
  
      post.properties = params
  
      if(post.save()) {
          print "hallo world"             
          redirect(action:'list', params:params)
      } else {
          render(view:'edit', model:[post:post])
      }
  }
  </code></pre>
  
  <p>The exception is thrown when I try to save the image at the DB.</p>
  
  <pre><code>2009-04-27 18:16:07,319 [20806951@qtp0-0] ERROR errors.GrailsExceptionResolver  - java.lang.ClassCastException: [B cannot be cast to java.sql.Blob
  </code></pre>
  
  <p>org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.ClassCastException: [B cannot be cast to java.sql.Blob</p>
  
  <p>Any hint why is this?</p>
  
  <p>BTW, I've seen in a tutorial that images were handled as strings but it didn't work
  as well.</p>