Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <g:form controller="post" action="save" enctype="multipart/form-data">
- My picture <input type="file" name="myPicture" />
- <g:submitButton name="submit" value="Save"/>
- </g:form>
- class Post {
- byte[] myPicture
- static mapping = {
- myPicture type: "blob"
- }
- static constraints = {
- myPicture(nullable:false)
- }
- }
- 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])
- }
- }
- 2009-04-27 18:16:07,319 [20806951@qtp0-0] ERROR errors.GrailsExceptionResolver - java.lang.ClassCastException: [B cannot be cast to java.sql.Blob
- def save = {
- def post = loadPost(params.id)
- def f = request.getFile('myPicture')
- post.myPicture = f.getBytes()
- post.pictureType = f.getContentType()
- if(post.save()) {
- 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')
- }
- }
Add Comment
Please, Sign In to add comment