Guest User

Untitled

a guest
Jun 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <g:form controller="post" action="save" enctype="multipart/form-data">
  2. My picture <input type="file" name="myPicture" />
  3. <g:submitButton name="submit" value="Save"/>
  4. </g:form>
  5.  
  6. class Post {
  7.  
  8. byte[] myPicture
  9.  
  10. static mapping = {
  11. myPicture type: "blob"
  12. }
  13.  
  14. static constraints = {
  15. myPicture(nullable:false)
  16. }
  17.  
  18. }
  19.  
  20. def save = {
  21. def post = loadPost(params.id)
  22.  
  23. post.properties = params
  24.  
  25. if(post.save()) {
  26. print "hallo world"
  27. redirect(action:'list', params:params)
  28. } else {
  29. render(view:'edit', model:[post:post])
  30. }
  31. }
  32.  
  33. 2009-04-27 18:16:07,319 [20806951@qtp0-0] ERROR errors.GrailsExceptionResolver - java.lang.ClassCastException: [B cannot be cast to java.sql.Blob
  34.  
  35. def save = {
  36.  
  37. def post = loadPost(params.id)
  38.  
  39. def f = request.getFile('myPicture')
  40.  
  41. post.myPicture = f.getBytes()
  42. post.pictureType = f.getContentType()
  43.  
  44.  
  45. if(post.save()) {
  46.  
  47. def upload = {
  48. def f = request.getFile('myFile')
  49. if(!f.empty) {
  50. f.transferTo( new File('/some/local/dir/myfile.txt') )
  51. response.sendError(200,'Done');
  52. }
  53. else {
  54. flash.message = 'file cannot be empty'
  55. render(view:'uploadForm')
  56. }
  57. }
Add Comment
Please, Sign In to add comment