grails - Class cast exception in Groovy -


I want to upload an image on the grails using groovy. My GSP page is as follows (I'm showing a simplified version of the original)

  & lt; G: form control = "post" action = "save" enctype = "multipart / form-data" & gt; My picture & lt; Input type = "file" name = "myPicture" /> & Lt; G: submitButton name = "submit" value = "save" /> & Lt; / G: form & gt;  

My domain class is as follows:

  class post {byte [myPicture static mapping = {myPicture type: "blob"}  

I need this mapping otherwise MySql will create a small blob that will be small to fit the images

  Fixed obstacles = {myPicture (nullable: false)} }  

I have an action on the controller that is saved which is as follows:

  def save = {def post = loadPost (params.id) Post.properties = params if (post.save ()) {print "Hello world" redirects (Image: Post: Post])}}  

When I click on the image on DB (action: 'list', parameters: parameters)} and {render (view: 'edit' I try to save, then the exception is thrown.

  2009-04-27 18: 16: 07,319 [20806951 @ qtp0-0] Error Errors. Greals Exceptionroller - java.lang.ClassCastException: [B] not put on java sql.blob  

o Rg.codehaus.groovy.runtime.InvokerInvocationException: java.lang.ClassCastException: [B can not be entered on java.sql.blob

< P> Why is there any indication?

BTW, I have seen in a tutorial that the images were controlled in the form of wires but it was not working properly.

Try this way:

  def save = {def Post = loadPost (params.id) def f = request.getFile ('myPicture') post. MyPicture = f.getBytes () post.pictureType = F.getContentType () if (post.save ()) { 

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -