# Halt file upload if maximum size is reached. Is that possible?

**URL:** <https://www.ruby-forum.com/t/halt-file-upload-if-maximum-size-is-reached-is-that-possible/144527>\
**Category:** Rails\
**Created:** [July 30, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/halt-file-upload-if-maximum-size-is-reached-is-that-possible/144527 "2008-07-30T17:02:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pahagon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ac8455/32.png) [@pahagon](https://www.ruby-forum.com/u/pahagon)\
**Post date:** [July 30, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/halt-file-upload-if-maximum-size-is-reached-is-that-possible/144527/1 "2008-07-30T17:02:04Z")

</div>

Hi guys.  
I’m building a rapidshare-like app, and as such each user has a disk  
quota. It’s possible to prevent a file save if it exceeds the free  
space, but I searched for an way to do the same _during_ the file  
upload. Using flash it’s apparently possible, but I don’t want to use  
flash.

One way to do it is via Apache configuration.

But, is there any other way to stop the transfer?

I considered attachment\_fu, which says in its config:  
“validates\_as\_attachment – This method prevents files outside of the  
valid range (:min\_size to :max\_size, or the :size range) from being  
saved. It does not however, halt the upload of such files. They will  
be uploaded into memory regardless of size before validation.”  
So, in attachment\_fu, this isn’t possible.

MAX\_FILE\_SIZE worked for PHP, but for Rails, apparently it doesn’t.

Thanks in advance for any help,

Paulo P.
