3

I can't read the file that I upload in Grails. write is the column in the db where I store the file that I uploaded.

CommonsMultipartFile testFile = request.getFile('templateFile')
InputStream inputStream = testFile.getInputStream()
bookInstance.write = inputStream
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
Simpson
  • 593
  • 5
  • 20

2 Answers2

4

There's many ways you can do it. Have a look:

uploading a file in grails

how to upload file into server directory with grails?

Multiple File Upload in Grails

and much more!

If you want the content of the file as a string you can do:

CommonsMultipartFile testFile = request.getFile('templateFile')
InputStream inputStream = testFile.getInputStream()
bookInstance.write = inputStream?.text

Notice the calling of getText() on the stream instance.

Community
  • 1
  • 1
defectus
  • 1,947
  • 2
  • 16
  • 21
0

Probabily you forgot to use a multipart encoded form: <form enctype="multipart/form-data">. In Grails, you can use a <g:uploadForm>. Could you check that in your gsp/html code?

albertovilches
  • 340
  • 1
  • 5