summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-01-09 10:02:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-01-09 10:02:16 +0000
commit4c75864948c6887c962a735c109a0a95cf0aea41 (patch)
treedf606f3104e658d23efa336376cc2bdf14501e77 /app
parent9d2474c234d74983e70374870f52ea1bf74ef92a (diff)
downloadredmine-4c75864948c6887c962a735c109a0a95cf0aea41.tar.gz
redmine-4c75864948c6887c962a735c109a0a95cf0aea41.zip
Merged r3258 and r3281 from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.9-stable@3286 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/attachments_controller.rb10
-rw-r--r--app/models/attachment.rb3
2 files changed, 12 insertions, 1 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 92d60ee0f..5b2acc8ab 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -41,7 +41,7 @@ class AttachmentsController < ApplicationController
# images are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
- :type => @attachment.content_type,
+ :type => detect_content_type(@attachment),
:disposition => (@attachment.image? ? 'inline' : 'attachment')
end
@@ -76,4 +76,12 @@ private
def delete_authorize
@attachment.deletable? ? true : deny_access
end
+
+ def detect_content_type(attachment)
+ content_type = attachment.content_type
+ if content_type.blank?
+ content_type = Redmine::MimeType.of(attachment.filename)
+ end
+ content_type.to_s
+ end
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index fe1d6afaa..e44b162ad 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -58,6 +58,9 @@ class Attachment < ActiveRecord::Base
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?
+ self.content_type = Redmine::MimeType.of(filename)
+ end
self.filesize = @temp_file.size
end
end