Uploading files - getting size


I want to get the size of an uploaded file that is saved in the
database. Can you help me?

In the edit view formular there is:

In the Attachment-model is:

def attachment=(attachment_field)
self.name = base_part_of(attachment_field.original_filename)
self.content_type = attachment_field.content_type.chomp
#self.size = attachment_field.file.size
self.data = attachment_field.read

def base_part_of file_name
name = File.basename(file_name)
name.gsub(/[^\w._-]/, ‘’)

In the project controller is (Attachments belong to projects):


Is it possible to get the filesize already before storing the data or do
I have to get it with a special function in the show view, where I want
to display it?

Thank you.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs