How to check the field 'Content-Length ' of an HTTP request using Ruby on Rails 3?

﹥>﹥吖頭↗ 提交于 2019-12-13 12:35:45

问题


I am using Ruby on Rails 3 and in a my view file I have this code:

<%= form_for (@account, ...) do |f| %>
  <%= f.file_field :file %>
  ...
  <%= f.submit "Upload" %>
<% end %>

In order to avoid an overloading of the server, I would check the size of the uploading file before that the server receives it. This is because, pressing the submit button of the form, the server first will entirely receive the file and after will check the file.

I know that a HTTP request has header fields, so I would like to check those for the uploading file, in particular, in my case, the Content-Length value.

How to do that?


回答1:


Did you try request.headers["content-length"] ?




回答2:


Doesn't nginx set a max file size too? Using that as your 'base' you can assure that the server will stop a big ass file upload. Maybe set it to the same max size if you are worried about this.



来源:https://stackoverflow.com/questions/4837014/how-to-check-the-field-content-length-of-an-http-request-using-ruby-on-rails

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