Class cast exception in Groovy

送分小仙女□ 提交于 2019-12-02 07:12:54

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()) {

I found a similar question on Nabble:

http://www.nabble.com/MySQL-and-Blobs-td16116885.html

Two possible solutions are suggested:

  • Change the constraints of the blob property to a large max-size, to stop it from using "TinyBlob".
  • Use the Hibernate Blob implementation instead of byte[] for the property's type declaration. This will require you stream data into the Blob, instead of direct assignment, but the post above gives code to do so.

Can you try using Spring's MultipartFile within your loadPost() method?

Here's an example from the docs:

def upload = {
    def f = request.getFile('myFile')
    if(!f.empty) {
      f.transferTo( new File('/some/local/dir/myfile.txt') )
      response.sendError(200,'Done');
    }    
    else {
       flash.message = 'file cannot be empty'
       render(view:'uploadForm')
    }
}

I believe you can access f.bytes directly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!