How to give users a file storage limit?

I am working on a web application right now using Rails and wanted to know if anyone knows of a good way to track file storage restrictions? We want to give users a certain amount of space that they can use to upload files, and we use paperclip to store it on Amazon S3. Any thoughts? Thanks

+7
ruby ruby-on-rails limits
source share
2 answers

One of the optional columns that you can use with paperclip is OBJECT_file_size, which you can summarize as

# Assuming a user has many files relationship @user.uploads.sum(:image_file_size) 

As for the actually imposed restriction, I would recommend creating a special check on any file model so that you can pass errors and return to the client.

+7
source share

The clipclip saves the file size.
That way, you can simply, for one user, do something like:

 def used_file_size self.files.sum(:document_file_size) end 

Then you will have the total size of all user documents.
Then you can add a maximum size limit and not check the document load if the user has reached that size.

+6
source share

All Articles