title: save a image in grails
body: <p>I have a field for image from which I want to save image to database. But it is showing casting exception. Can anyone please help me on this please? I am using grails 2.1.0. here is my code below :</p>
  
  <p>my view page >>></p>
  
  <pre><code>&lt;g:uploadForm action="upload"&gt;
  
  Photo: &lt;input name="photo" type="file" /&gt;
  &lt;g:submitButton name="upload" value="Upload"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>my controller action >>></p>
  
  <pre><code>def upload={
    def user = User.findById(1)
       user.avatar = params.photo
       user.save()
  }
  </code></pre>
  
  <p>my domain class >>></p>
  
  <pre><code>   class User {
  
      String username
      byte[] avatar
      String avatarType
  
      static constraints = {
          avatar(nullable:true, maxSize: 1024 * 1024 * 2 /* 2MB */)
          avatarType(nullable:true)
      }
  
  }
  </code></pre>