diff options
author | Go MAEDA <maeda@farend.jp> | 2021-08-15 04:17:41 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-08-15 04:17:41 +0000 |
commit | 9e8ce765d7a9fce650b9ecea8ddf95a9ea7f9f6b (patch) | |
tree | 32c0aac3aea65fb18a2c85534bb05a383669c6be /app | |
parent | a992e724fb3a7309dfc307e0e52a46382a52e809 (diff) | |
download | redmine-9e8ce765d7a9fce650b9ecea8ddf95a9ea7f9f6b.tar.gz redmine-9e8ce765d7a9fce650b9ecea8ddf95a9ea7f9f6b.zip |
Merged r21173 from trunk to 4.2-stable (#35715).
git-svn-id: http://svn.redmine.org/redmine/branches/4.2-stable@21174 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/attachments_controller.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 8e28194a3..91cd7ce41 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -105,7 +105,7 @@ class AttachmentsController < ApplicationController return end - @attachment = Attachment.new(:file => request.body) + @attachment = Attachment.new(:file => raw_request_body) @attachment.author = User.current @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16) @attachment.content_type = params[:content_type].presence @@ -303,4 +303,14 @@ class AttachmentsController < ApplicationController def update_all_params params.permit(:attachments => [:filename, :description]).require(:attachments) end + + # Get an IO-like object for the request body which is usable to create a new + # attachment. We try to avoid having to read the whole body into memory. + def raw_request_body + if request.body.respond_to?(:size) + request.body + else + request.raw_post + end + end end |