Skip to content

Instantly share code, notes, and snippets.

@nbkhope
Created January 16, 2017 03:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nbkhope/006e6b82d8f118d5cdd630c5e394134d to your computer and use it in GitHub Desktop.
Save nbkhope/006e6b82d8f118d5cdd630c5e394134d to your computer and use it in GitHub Desktop.
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
}
@ppazos
Copy link

ppazos commented Jun 12, 2020

How do you handle FileUploadBase$SizeLimitExceededException when the size is bigger than the max allowed?

@rmarquezromero
Copy link

How do you handle FileUploadBase$SizeLimitExceededException when the size is bigger than the max allowed?

Hola Pablo,

¿Conseguiste capturar la excepción en Grails 3.3.x?

@ppazos
Copy link

ppazos commented May 18, 2021

@rmarquezromero no he podido porque la excepción ocurre antes de llegar a los controllers y nadie ha provisto una solución que funcione en Grails 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment