# Is it possible to determine the file size before an actual u

**URL:** <https://www.ruby-forum.com/t/is-it-possible-to-determine-the-file-size-before-an-actual-u/88829>\
**Category:** Rails\
**Created:** [March 14, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-determine-the-file-size-before-an-actual-u/88829 "2007-03-14T20:05:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan\_kuwachi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@dan\_kuwachi](https://www.ruby-forum.com/u/dan_kuwachi)\
**Post date:** [March 14, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-determine-the-file-size-before-an-actual-u/88829/1 "2007-03-14T20:05:59Z")

</div>

I am doing a file upload where I want to constrain the maximum size to  
1 mb, and I can check this data after the upload has completed. Is  
there a way to check this before the upload actually starts?

---

<div class="post-metadata">

**Author:** ![dan\_kuwachi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@dan\_kuwachi](https://www.ruby-forum.com/u/dan_kuwachi)\
**Post date:** [March 14, 2007, 8:13pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-determine-the-file-size-before-an-actual-u/88829/2 "2007-03-14T20:13:27Z")

</div>

dan kuwachi wrote:

> I am doing a file upload where I want to constrain the maximum size to  
> 1 mb, and I can check this data after the upload has completed. Is  
> there a way to check this before the upload actually starts?

I don’t think you can do this. Rails will not even begin processing the  
action until the browser finishes sending the request. And the file  
upload is part of the request. I think you are at the mercy of HTTP  
here.

But I could be completely wrong since I have heard of rails based file  
upload progress bars, so if anyone knows better feel free to shoot me  
down.

---

<div class="post-metadata">

**Author:** ![dan\_kuwachi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@dan\_kuwachi](https://www.ruby-forum.com/u/dan_kuwachi)\
**Post date:** [March 15, 2007, 1:45am UTC](https://www.ruby-forum.com/t/is-it-possible-to-determine-the-file-size-before-an-actual-u/88829/3 "2007-03-15T01:45:45Z")

</div>

If you’re using mongrel, you can write a handler to get information  
about the incoming request before it’s completely downloaded. You can  
then have your rails controllers connect to the handler via drb to get  
the content-length information the browser sends.

Afaik, this is what mongrel’s upload progress handler does:

[http://mongrel.rubyforge.org/docs/upload\_progress.html](http://mongrel.rubyforge.org/docs/upload_progress.html)

It’ll probably do what you need to do. If not, you can use it as  
inspiration for your own handler.
