##// END OF EJS Templates
Send the content type as parameter when uploading a file....
Jean-Philippe Lang -
r13406:93690ee83032
parent child
Show More
@@ -86,6 +86,7 class AttachmentsController < ApplicationController
86 @attachment = Attachment.new(:file => request.raw_post)
86 @attachment = Attachment.new(:file => request.raw_post)
87 @attachment.author = User.current
87 @attachment.author = User.current
88 @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
88 @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
89 @attachment.content_type = params[:content_type].presence
89 saved = @attachment.save
90 saved = @attachment.save
90
91
91 respond_to do |format|
92 respond_to do |format|
@@ -94,6 +94,7 function uploadBlob(blob, uploadUrl, attachmentId, options) {
94 uploadUrl = uploadUrl + '?attachment_id=' + attachmentId;
94 uploadUrl = uploadUrl + '?attachment_id=' + attachmentId;
95 if (blob instanceof window.File) {
95 if (blob instanceof window.File) {
96 uploadUrl += '&filename=' + encodeURIComponent(blob.name);
96 uploadUrl += '&filename=' + encodeURIComponent(blob.name);
97 uploadUrl += '&content_type=' + encodeURIComponent(blob.type);
97 }
98 }
98
99
99 return $.ajax(uploadUrl, {
100 return $.ajax(uploadUrl, {
@@ -33,6 +33,16 class AttachmentsTest < Redmine::IntegrationTest
33 assert_equal 'text/plain', attachment.content_type
33 assert_equal 'text/plain', attachment.content_type
34 end
34 end
35
35
36 def test_upload_should_accept_content_type_param
37 log_user('jsmith', 'jsmith')
38 assert_difference 'Attachment.count' do
39 post "/uploads.js?attachment_id=1&filename=foo&content_type=image/jpeg", "File content", {"CONTENT_TYPE" => 'application/octet-stream'}
40 assert_response :success
41 end
42 attachment = Attachment.order(:id => :desc).first
43 assert_equal 'image/jpeg', attachment.content_type
44 end
45
36 def test_upload_as_js_and_attach_to_an_issue
46 def test_upload_as_js_and_attach_to_an_issue
37 log_user('jsmith', 'jsmith')
47 log_user('jsmith', 'jsmith')
38
48
General Comments 0
You need to be logged in to leave comments. Login now