Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grails 3 File Upload
// In your controller, use the following code
// Single file
def file = request.getFile("identifier_name_in_html_tag_attribute")
// Useful information
file.empty
file.class // => class org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile
file.name // the name attribute value you used above (comes from html input tag)
file.originalFilename
file.size
file.contentType // e.g. "image/png"
// Multiple files
request.getFiles("pictures[]").each {
// use closure parameter if you don't want to use "it"
//file -> println(file.originalFilename)
println it.originalFilename
}
// This also works:
request.multiFileMap.get("pictures[]").each {
print it.originalFilename
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.