Browse Source

Let the attachment filename be specified on upload (#12125).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10678 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/2.2.0
Jean-Philippe Lang 11 years ago
parent
commit
251f263abd

+ 1
- 1
app/controllers/attachments_controller.rb View File

@@ -84,7 +84,7 @@ class AttachmentsController < ApplicationController

@attachment = Attachment.new(:file => request.raw_post)
@attachment.author = User.current
@attachment.filename = Redmine::Utils.random_hex(16)
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)

if @attachment.save
respond_to do |format|

+ 12
- 0
test/integration/api_test/attachments_test.rb View File

@@ -117,6 +117,18 @@ class ApiTest::AttachmentsTest < ActionController::IntegrationTest
assert_equal token, attachment.token
end

test "POST /uploads.xml should accept :filename param as the attachment filename" do
set_tmp_attachments_directory
assert_difference 'Attachment.count' do
post '/uploads.xml?filename=test.txt', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
assert_response :created
end

attachment = Attachment.order('id DESC').first
assert_equal 'test.txt', attachment.filename
assert_match /_test\.txt$/, attachment.diskfile
end

test "POST /uploads.xml should not accept other content types" do
set_tmp_attachments_directory
assert_no_difference 'Attachment.count' do

Loading…
Cancel
Save