##// END OF EJS Templates
Let the attachment filename be specified on upload (#12125)....
Jean-Philippe Lang -
r10467:251f263abdc5
parent child
Show More
@@ -84,7 +84,7 class AttachmentsController < ApplicationController
84 84
85 85 @attachment = Attachment.new(:file => request.raw_post)
86 86 @attachment.author = User.current
87 @attachment.filename = Redmine::Utils.random_hex(16)
87 @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
88 88
89 89 if @attachment.save
90 90 respond_to do |format|
@@ -117,6 +117,18 class ApiTest::AttachmentsTest < ActionController::IntegrationTest
117 117 assert_equal token, attachment.token
118 118 end
119 119
120 test "POST /uploads.xml should accept :filename param as the attachment filename" do
121 set_tmp_attachments_directory
122 assert_difference 'Attachment.count' do
123 post '/uploads.xml?filename=test.txt', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
124 assert_response :created
125 end
126
127 attachment = Attachment.order('id DESC').first
128 assert_equal 'test.txt', attachment.filename
129 assert_match /_test\.txt$/, attachment.diskfile
130 end
131
120 132 test "POST /uploads.xml should not accept other content types" do
121 133 set_tmp_attachments_directory
122 134 assert_no_difference 'Attachment.count' do
General Comments 0
You need to be logged in to leave comments. Login now