return
end
- @attachment = Attachment.new(:file => request.raw_post)
+ @attachment = Attachment.new(:file => request.body)
@attachment.author = User.current
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
@attachment.content_type = params[:content_type].presence
end
end
end
+
+# https://github.com/rack/rack/pull/1703
+# TODO: remove this when Rack is updated to 3.0.0
+require 'rack'
+module Rack
+ class RewindableInput
+ unless method_defined?(:size)
+ def size
+ make_rewindable unless @rewindable_io
+ @rewindable_io.size
+ end
+ end
+ end
+end
assert attachment.digest.present?
assert File.exist? attachment.diskfile
end
+
+ test "POST /uploads.json should be compatible with an fcgi's input" do
+ set_tmp_attachments_directory
+ assert_difference 'Attachment.count' do
+ post(
+ '/uploads.json',
+ :headers => {
+ "CONTENT_TYPE" => 'application/octet-stream',
+ "CONTENT_LENGTH" => '12',
+ "rack.input" => Rack::RewindableInput.new(StringIO.new('File content'))
+ }.merge(credentials('jsmith'))
+ )
+ assert_response :created
+ end
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json['upload']
+ token = json['upload']['token']
+ assert token.present?
+ assert attachment = Attachment.find_by_token(token)
+ assert_equal 12, attachment.filesize
+ assert File.exist? attachment.diskfile
+ end
end