user502052
user502052

Reputation: 15257

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

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?

Upvotes: 2

Views: 3546

Answers (2)

pjammer
pjammer

Reputation: 9577

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.

Upvotes: 1

Jeff Paquette
Jeff Paquette

Reputation: 7127

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

Upvotes: 2

Related Questions