Rails file upload size limit

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 21:41:50

Or if you're using nginx with passenger, add in the server block:

server {
  client_max_body_size 100M;
}

http://wiki.nginx.org/NginxHttpCoreModule#client_max_body_size

You may cap the upload size via Apache using the LimitRequestBody directive:

<Directory "/var/www">
    LimitRequestBody 1024
</Directory>

http://httpd.apache.org/docs/1.3/mod/core.html#limitrequestbody

pratik

You can use following javascript to notify user that the selected file exceeds maximum limit. But still its essential to have server side validation.

$('#id_of_input_file_field').change(function() {
  if(this.files[0].size > MAX_LIMIT_FOR_FILE){
    $('#id_of_input_file_field').val(''); 
    alert('File exceeds maximum size limit ')
}
});

MAX_LIMIT_FOR_FILE is in byte so if you want set max limit of 1Mb then value of MAX_LIMIT_FOR_FILE should be 1048576

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!