Created
January 16, 2017 03:49
-
-
Save nbkhope/006e6b82d8f118d5cdd630c5e394134d to your computer and use it in GitHub Desktop.
Grails 3 File Upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
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?
@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
How do you handle FileUploadBase$SizeLimitExceededException when the size is bigger than the max allowed?