上传文件大小检查Grails [英] Uploading file size check Grails

查看:169
本文介绍了上传文件大小检查Grails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Grails进行文件上传时遇到了一个问题。
我想检查从Windows资源管理器打开后的文件大小运行时,并给我错误消息,如果任何条件失败。

我有一个文件上传窗口,我有3个文件选择选项。我想检查每个三个文件不要超过5MB。当我点击浏览按钮时,我的系统资源管理器打开,我选择文件。



有没有什么办法在使用javascript / Ajax调用选择文件时检查文件大小?如果文件大小超过浏览器再次显示选择另一个文件。

解决方案

关于这个问题,有一个插件-in打电话给进行救援。



使用此插件,您可以在config.groovy中定义一些限制。这是一个例子:

  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 /



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.

解决方案

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/"
    }
}

这篇关于上传文件大小检查Grails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆