2

I'm trying to upload an image to the DB but when I try to see what is in the params, I find in fileupload is the image's name something like org.springframework.web.multipart.commons.CommonsMultipartFile@eeed792. For example params [fileupload:android-logo.jpg].

Here is the domain class:

class Photos {
Date dateCreated
byte [] photo
Date lastUpdated

static constraints = {

}
static mapping ={ photo(sqlType:"BLOB") }
}

the GSP :

 <label>Photos:</label>
            <input class="inputFiles" type="file" name="fileupload" multiple="multiple" accept="image/*" />

What may be causing this ?

elixir
  • 1,394
  • 1
  • 11
  • 21
Sherif
  • 421
  • 3
  • 15
  • sounds like it is going to be a huge database. Why not store a reference to the file i.e. Sha string of it and store the file on filesystem - nightmare DB management / backup / restore.. – V H Jun 14 '16 at 09:37

1 Answers1

1

File uploads don't get directly injected into params. You have to use request.getFile('paramname')

Take a look at this: http://www.slideshare.net/cavneb/upload-files-with-grails

billjamesdev
  • 14,554
  • 6
  • 53
  • 76
  • after adding `enctype='multipart/form-data'` to the `form` solved the problem , but how to handle the `org.springframework.web.multipart.commons.CommonsMultipartFile` when adding `multiple="multiple"` to the uploading field to upload multiple images . – Sherif Jun 14 '16 at 14:48
  • 1
    Another search yields: http://stackoverflow.com/questions/10425891/multiple-file-input-type-upload-in-grails, or there's a plugin https://grails.org/plugin/uploadr – billjamesdev Jun 14 '16 at 14:50