如何使用Ruby on Rails 3检查HTTP请求的字段'Content-Length'? [英] How to check the field 'Content-Length ' of an HTTP request using Ruby on Rails 3?

查看:140
本文介绍了如何使用Ruby on Rails 3检查HTTP请求的字段'Content-Length'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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.

我知道 HTTP请求有标题字段,所以我想检查一下上传文件,特别是在我的情况下, 内容长度值。

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.

怎么做?

推荐答案

你试过 request.headers [content-length]

这篇关于如何使用Ruby on Rails 3检查HTTP请求的字段'Content-Length'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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