mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-09 09:01:31 +00:00
Attachment content type not set when uploading attachment (#18667).
git-svn-id: http://svn.redmine.org/redmine/trunk@13787 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b8a586c475
commit
64763bece3
@ -52,7 +52,7 @@ class Attachment < ActiveRecord::Base
|
||||
cattr_accessor :thumbnails_storage_path
|
||||
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
|
||||
|
||||
before_save :files_to_final_location
|
||||
before_create :files_to_final_location
|
||||
after_destroy :delete_from_disk
|
||||
|
||||
# Returns an unsaved copy of the attachment
|
||||
@ -80,9 +80,6 @@ class Attachment < ActiveRecord::Base
|
||||
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
|
||||
@ -124,6 +121,10 @@ class Attachment < ActiveRecord::Base
|
||||
self.digest = md5.hexdigest
|
||||
end
|
||||
@temp_file = nil
|
||||
|
||||
if content_type.blank? && filename.present?
|
||||
self.content_type = Redmine::MimeType.of(filename)
|
||||
end
|
||||
# Don't save the content type if it's longer than the authorized length
|
||||
if self.content_type && self.content_type.length > 255
|
||||
self.content_type = nil
|
||||
|
||||
@ -23,6 +23,16 @@ class AttachmentsTest < Redmine::IntegrationTest
|
||||
:trackers, :projects_trackers,
|
||||
:issue_statuses, :enumerations
|
||||
|
||||
def test_upload_should_set_default_content_type
|
||||
log_user('jsmith', 'jsmith')
|
||||
assert_difference 'Attachment.count' do
|
||||
post "/uploads.js?attachment_id=1&filename=foo.txt", "File content", {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||
assert_response :success
|
||||
end
|
||||
attachment = Attachment.order(:id => :desc).first
|
||||
assert_equal 'text/plain', attachment.content_type
|
||||
end
|
||||
|
||||
def test_upload_as_js_and_attach_to_an_issue
|
||||
log_user('jsmith', 'jsmith')
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user