# Limit disk space allocation

**URL:** <https://www.ruby-forum.com/t/limit-disk-space-allocation/182965>\
**Category:** Rails\
**Created:** [February 5, 2010, 10:40am UTC](https://www.ruby-forum.com/t/limit-disk-space-allocation/182965 "2010-02-05T10:40:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prabesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@prabesh](https://www.ruby-forum.com/u/prabesh)\
**Post date:** [February 5, 2010, 10:40am UTC](https://www.ruby-forum.com/t/limit-disk-space-allocation/182965/1 "2010-02-05T10:40:10Z")

</div>

I have a project management application . Anyone can sign up but as  
the space is limited, I need to limit the space for each user so they  
can’t upload more than the allocated quota.  
How Can I allocate the fixed space for the created user?

---

<div class="post-metadata">

**Author:** ![prabesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@prabesh](https://www.ruby-forum.com/u/prabesh)\
**Post date:** [February 5, 2010, 10:48am UTC](https://www.ruby-forum.com/t/limit-disk-space-allocation/182965/2 "2010-02-05T10:48:21Z")

</div>

How are you keeping track of what they have uploaded? If its in a  
database  
just include the sizes and when they upload something new you could just  
reject it if the new file will push them over quota. If you just have  
them  
in a directory per user then a quick scan over the directory should  
suffice.

How can you stop them uploading something that is too big to upload in  
the  
first place? Maybe something can be done in Javascript and or Flash.  
There  
are a few file uploaders available, maybe they could be modified to  
check  
the size of the file being uploaded before it is uploaded and pop up an  
alert if the new file will take you over quota. Much better than letting  
the  
user upload a file and then saying “Over quota, file deleted”.

However I am not an expert on Javascript so I could be talking out of my  
bum. Maybe someone more knowledgeable could chip in.

---

<div class="post-metadata">

**Author:** ![prabesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@prabesh](https://www.ruby-forum.com/u/prabesh)\
**Post date:** [February 5, 2010, 11:15am UTC](https://www.ruby-forum.com/t/limit-disk-space-allocation/182965/3 "2010-02-05T11:15:53Z")

</div>

> Much better than letting the user upload a file and then saying “Over quota \> file deleted”.

You’d have to check the file on server side too, as javascript alone  
cant guarantee that the file wont be uploaded anyway. To check on the  
serverside the whole file has to be uploaded first before you can check  
its size.  
Javascript should only be used for userfriendliness. For instance, if  
the files are big they will take a while to upload and then it might be  
a good idea to try and check it with javascript beforehand. If the files  
are small, you might as well do it all on the server side, as the user  
wont notice much difference anyway.

All of that being said, I belive your web site would have to be in the  
browsers “trusted zone” before you’d have access to read files with  
javascript anyway, so its probably not an option.

---

<div class="post-metadata">

**Author:** ![prabesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@prabesh](https://www.ruby-forum.com/u/prabesh)\
**Post date:** [February 5, 2010, 9:03pm UTC](https://www.ruby-forum.com/t/limit-disk-space-allocation/182965/4 "2010-02-05T21:03:00Z")

</div>

Sharagoz – wrote:

> > Much better than letting the user upload a file and then saying “Over quota \> file deleted”.
> 
> You’d have to check the file on server side too, as javascript alone  
> cant guarantee that the file wont be uploaded anyway. To check on the  
> serverside the whole file has to be uploaded first before you can check  
> its size.  
> Javascript should only be used for userfriendliness. For instance, if  
> the files are big they will take a while to upload and then it might be  
> a good idea to try and check it with javascript beforehand. If the files  
> are small, you might as well do it all on the server side, as the user  
> wont notice much difference anyway.
> 
> All of that being said, I belive your web site would have to be in the  
> browsers “trusted zone” before you’d have access to read files with  
> javascript anyway, so its probably not an option.

JavaScript in a Web browser cannot touch the client’s filesystem at all.  
I don’t know if it has access to size information of a file that’s in a  
file field.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
