Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top