mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-23 17:01:13 +00:00
Send the content type as parameter when uploading a file.
git-svn-id: http://svn.redmine.org/redmine/trunk@13788 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
64763bece3
commit
93690ee830
@ -86,6 +86,7 @@ class AttachmentsController < ApplicationController
|
|||||||
@attachment = Attachment.new(:file => request.raw_post)
|
@attachment = Attachment.new(:file => request.raw_post)
|
||||||
@attachment.author = User.current
|
@attachment.author = User.current
|
||||||
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||||
|
@attachment.content_type = params[:content_type].presence
|
||||||
saved = @attachment.save
|
saved = @attachment.save
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|||||||
@ -94,6 +94,7 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
|
|||||||
uploadUrl = uploadUrl + '?attachment_id=' + attachmentId;
|
uploadUrl = uploadUrl + '?attachment_id=' + attachmentId;
|
||||||
if (blob instanceof window.File) {
|
if (blob instanceof window.File) {
|
||||||
uploadUrl += '&filename=' + encodeURIComponent(blob.name);
|
uploadUrl += '&filename=' + encodeURIComponent(blob.name);
|
||||||
|
uploadUrl += '&content_type=' + encodeURIComponent(blob.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $.ajax(uploadUrl, {
|
return $.ajax(uploadUrl, {
|
||||||
|
|||||||
@ -33,6 +33,16 @@ class AttachmentsTest < Redmine::IntegrationTest
|
|||||||
assert_equal 'text/plain', attachment.content_type
|
assert_equal 'text/plain', attachment.content_type
|
||||||
end
|
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
|
def test_upload_as_js_and_attach_to_an_issue
|
||||||
log_user('jsmith', 'jsmith')
|
log_user('jsmith', 'jsmith')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user