0

I am facing a problem regarding file uploading in Grails. I would like to check the file size runtime after opening from the windows explorer and give me the error message if any condition fails.

I have a file uploading window where I have 3 file choose options. I would like to check each three files not to be more than 5MB. When I click on Browse button then my system explorer opens and I choose file.

Is there any way to check file size while selecting the file using javascript/ Ajax call? And if the file size is exceeds than the explorer show again to choose another file.

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156

1 Answers1

0

About this issue, there is a plug-in called file-uploader to the rescue.

With this plug-in you can define some restrictions in config.groovy. Here is an example:

fileuploader {
    avatar {
        maxSize = 1024 * 256 //256 kbytes
        allowedExtensions = ["jpg","jpeg","gif","png"]
        path = "/tmp/avatar/"
    }
    docs {
        maxSize = 1000 * 1024 * 4 //4 mbytes
        allowedExtensions = ["doc", "docx", "pdf", "rtf"]
        path = "/tmp/docs/"
    }
}
coderLMN
  • 3,076
  • 1
  • 21
  • 26