# How to check file size before file upload completes?

**URL:** <https://www.ruby-forum.com/t/how-to-check-file-size-before-file-upload-completes/137845>\
**Category:** Rails\
**Created:** [May 16, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/how-to-check-file-size-before-file-upload-completes/137845 "2008-05-16T21:29:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickname123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e79b87/32.png) [@nickname123](https://www.ruby-forum.com/u/nickname123)\
**Post date:** [May 16, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/how-to-check-file-size-before-file-upload-completes/137845/1 "2008-05-16T21:29:04Z")

</div>

Is it possible to check a file’s size before a file upload completes?  
We want to limit file uploads early by checking the header’s content  
length from the request object. The controller action and  
before\_filter doesn’t seem to run until the file finishes uploading.

---

<div class="post-metadata">

**Author:** ![nickname123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e79b87/32.png) [@nickname123](https://www.ruby-forum.com/u/nickname123)\
**Post date:** [May 16, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/how-to-check-file-size-before-file-upload-completes/137845/2 "2008-05-16T21:40:49Z")

</div>

On 16 May 2008, at 20:09, nickname wrote:

> Is it possible to check a file’s size before a file upload completes?  
> We want to limit file uploads early by checking the header’s content  
> length from the request object. The controller action and  
> before\_filter doesn’t seem to run until the file finishes uploading.

Use a Flash uploader, it will even do clientside filesize validation.  
[SWFupload.org](http://SWFupload.org) is one of them. They do have some gotchas with Rails  
cookie store and sessions, but you can find more information on that  
by searching the list archives.

Best regards

Peter De Berdt
