Hi,
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:
<input id="attachment_title" name="attachment[title]"
size="30"
type="text" /> <input id="attachment_attachment"
name="attachment[attachment]" size="30"
type="file" />
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
end
def base_part_of file_name
name = File.basename(file_name)
name.gsub(/[^\w._-]/, '''')
end
In the project controller is (Attachments belong to projects):
project.attachments.create(params[:attachment])
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.
--
Posted via http://www.ruby-forum.com/.