Skip to content

Instantly share code, notes, and snippets.

@nbkhope
nbkhope / grails-unit-testing-controller.groovy
Created January 20, 2017 21:02
Grails 3 Unit Testing (Controller)
// Given the controller
class DemoController {
def hello() {
render "greetings!"
}
def greet() {
redirect action: 'hello'
}
}
@nbkhope
nbkhope / grailsFileUpload.groovy
Created January 16, 2017 03:49
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