Home Uploading a large file (>1GB) to grails3
Reply: 1

Uploading a large file (>1GB) to grails3

user39950 Published in 2018-01-09 08:08:14Z

Uploading a large file (>1GB) to a grails, I only need to access it via stream, no need to save the entire file to disk or RAM. However how can I access the upload stream? I tried with an Interceptor:

class UploadLargeFileInterceptor {


UploadLargeFileInterceptor() {
    match(controller:"apiv2", action:"uploadLarge")

boolean before() {

    log.error(request.getInputStream().text.length() as String)

boolean after() {


void afterView() {
    // no-op

but stream length is always 0 and in the controller there is a multipart file which I am trying to avoid because it will store the whole file. Any ideas?

Mamun Sardar
Mamun Sardar Reply to 2018-01-14 09:11:03Z

No need for an interceptor. You can access user uploaded file stream like this inside controller:

MultipartFile uploadedFile = params.filename as MultipartFile
println "file original name" + uploadedFile.originalFilename
println "file content type" + uploadedFile.contentType
println "file size" + uploadedFile.size //consider as stream length
InputStream inputStream = uploadedFile.getInputStream() //access the input stream

Also make sure to allow max size in application.groovy like this:

grails.controllers.upload.maxFileSize = 1572864000 //1500MB (X MB * 1024 * 1024)
grails.controllers.upload.maxRequestSize = 1572864000 //1500MB

Or if you are running behind on webserver like nginx, tune that request & timeout config also.

With the above code and -Xms512m -Xmx1G heap size I uploaded 1.25Gb file with no issue. If you are uploading to file storage / cloud storage, make sure that lib uses stream like:

File: org.apache.commons.io.FileUtils.copyToFile(inputStream, new File('<file path>')) Azure: storageBlob.upload(inputStream, length)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.406938 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO