Yes it is possible. You can use papreclip to control file downloads (or any other authoritative plugin / download control stone). Most of these tools give you access to the size of the downloaded file. You can just save these files in the database along with asset_uri (which I assume you already have) and check if the user can upload another file, just sum all the sizes of all assets with the corresponding user_id.
Users:
id
email_address
first_name
upload_limit
Assets:
id
user_id
uri
filesize
filename
Then, to capture the total size of the downloaded files by a specific user, you can do:
class User < ActiveRecord::Base
has_many :assets
def can_upload?
if Asset.sum('filesize', :conditions => 'user_id = #{self.id}') >= self.upload_limit
return false
else
return true
end
end
def used_storage
return Asset.sum('filesize', :conditions => 'user_id = #{self.id}')
end
def available_storage
if self.can_upload?
return self.upload_limit - Asset.sum('filesize', :conditions => 'user_id = #{self.id}')
else
return 0
end
end
end
, ActiveRecord sum , . Ruby.