Grails File Upload Example

I encountered several examples of uploading files with Grails, but none worked reliably for me. Therefore, I’m sharing a snippet of code that is actually functional (at least in my environment). Hopefully, someone else finds it useful.

Controller Method

The controller method looks like this:

// inputTagName should be "myFile"
public MultipartFile readUploadFile(HttpServletRequest request,
                                    String inputTagName) {
  return request.getFile(inputTagName)
}

GSP Page Snippet

Here is the GSP page snippet:

<g:uploadForm name="myUpload" action="readUploadFile">
  <input type="file" name="myFile" />
  <g:submitButton class="button" name="Upload" value="Upload" />
</g:uploadForm>




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Amplifier vs Claude Code — where Microsoft’s Agent Framework fits in
  • Optimizing Large Language Models A Look at Key Techniques
  • Nginx Reverse Proxy for Amazon OpenSearch Kibana with Ansible
  • Terraform Example: Serverless React App with AWS API Gateway and Lambda
  • Application Load Balancer - Host- and Path-Based Routing for Multiple ECS Services