diff options
-rw-r--r-- | app/controllers/attachments_controller.rb | 1 | ||||
-rw-r--r-- | public/javascripts/attachments.js | 1 | ||||
-rw-r--r-- | test/integration/attachments_test.rb | 10 |
3 files changed, 12 insertions, 0 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 924e9a186..d9357fbbd 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -86,6 +86,7 @@ class AttachmentsController < ApplicationController @attachment = Attachment.new(:file => request.raw_post) @attachment.author = User.current @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16) + @attachment.content_type = params[:content_type].presence saved = @attachment.save respond_to do |format| diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index f80098665..dea928f26 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -94,6 +94,7 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) { uploadUrl = uploadUrl + '?attachment_id=' + attachmentId; if (blob instanceof window.File) { uploadUrl += '&filename=' + encodeURIComponent(blob.name); + uploadUrl += '&content_type=' + encodeURIComponent(blob.type); } return $.ajax(uploadUrl, { diff --git a/test/integration/attachments_test.rb b/test/integration/attachments_test.rb index 646382a42..bb3de7548 100644 --- a/test/integration/attachments_test.rb +++ b/test/integration/attachments_test.rb @@ -33,6 +33,16 @@ class AttachmentsTest < Redmine::IntegrationTest assert_equal 'text/plain', attachment.content_type end + def test_upload_should_accept_content_type_param + log_user('jsmith', 'jsmith') + assert_difference 'Attachment.count' do + post "/uploads.js?attachment_id=1&filename=foo&content_type=image/jpeg", "File content", {"CONTENT_TYPE" => 'application/octet-stream'} + assert_response :success + end + attachment = Attachment.order(:id => :desc).first + assert_equal 'image/jpeg', attachment.content_type + end + def test_upload_as_js_and_attach_to_an_issue log_user('jsmith', 'jsmith') |