summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-02-23 10:01:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-02-23 10:01:16 +0000
commit77626ef6fbf2df028ccf01f6a72e459bfc70e2ab (patch)
tree226c3c315e1f3d3162dfac14535821156c703532 /app/models
parentd086683b17665719aa352074288b90ba954e6db0 (diff)
downloadredmine-77626ef6fbf2df028ccf01f6a72e459bfc70e2ab.tar.gz
redmine-77626ef6fbf2df028ccf01f6a72e459bfc70e2ab.zip
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
Diffstat (limited to 'app/models')
-rw-r--r--app/models/attachment.rb21
1 files changed, 16 insertions, 5 deletions
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