From 77626ef6fbf2df028ccf01f6a72e459bfc70e2ab Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 23 Feb 2012 10:01:16 +0000 Subject: Adds support for adding attachments to issues through the REST API (#8171). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8928 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'app/models') diff --git a/app/models/attachment.rb b/app/models/attachment.rb index d87a9df4c..84e945c44 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -76,21 +76,32 @@ class Attachment < ActiveRecord::Base unless incoming_file.nil? @temp_file = incoming_file if @temp_file.size > 0 - self.filename = sanitize_filename(@temp_file.original_filename) - self.disk_filename = Attachment.disk_filename(filename) - self.content_type = @temp_file.content_type.to_s.chomp - if content_type.blank? + if @temp_file.respond_to?(:original_filename) + self.filename = @temp_file.original_filename + end + if @temp_file.respond_to?(:content_type) + self.content_type = @temp_file.content_type.to_s.chomp + end + if content_type.blank? && filename.present? self.content_type = Redmine::MimeType.of(filename) end self.filesize = @temp_file.size end end end - + def file nil end + def filename=(arg) + write_attribute :filename, sanitize_filename(arg.to_s) + if new_record? && disk_filename.blank? + self.disk_filename = Attachment.disk_filename(filename) + end + filename + end + # Copies the temporary file to its final location # and computes its MD5 hash def files_to_final_location -- cgit v1.2.3