]> source.dussan.org Git - redmine.git/commitdiff
Merged r20993 from trunk to 4.1-stable (#33752).
authorGo MAEDA <maeda@farend.jp>
Wed, 12 May 2021 02:36:53 +0000 (02:36 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 12 May 2021 02:36:53 +0000 (02:36 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@20995 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/attachments_controller.rb
config/initializers/10-patches.rb
test/integration/api_test/attachments_test.rb

index 4a880793e128b1147cf278a4f0b5c7567aa82cdc..c2f6481f3758f58ae63bfc0a88b3dbe43856d3ba 100644 (file)
@@ -101,7 +101,7 @@ class AttachmentsController < ApplicationController
       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
index 9af59563e098cdb54297079a421bdccb1ab9ccd1..204caba9a2f1fdf12ca03ffa32de8d534518a4b3 100644 (file)
@@ -213,3 +213,17 @@ module ActionView
     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
index f63c2b0571d09e85301e30ddf65fb5e0f1beba89..7b4d60b80a70d926f4f437b2d0983428663e564f 100644 (file)
@@ -229,4 +229,26 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
     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