diff options
author | Go MAEDA <maeda@farend.jp> | 2021-08-15 04:19:30 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-08-15 04:19:30 +0000 |
commit | 41ca940f66e6f683d45f78dbb63e89f5a17e1e80 (patch) | |
tree | 654f47a1e0f95d4cd82245894aa6c8556c111ddf /app | |
parent | 2af371526c89d9c5b3d1d435188d2b2473eafa4c (diff) | |
download | redmine-41ca940f66e6f683d45f78dbb63e89f5a17e1e80.tar.gz redmine-41ca940f66e6f683d45f78dbb63e89f5a17e1e80.zip |
Merged r21173 from trunk to 4.1-stable (#35715).
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@21175 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 c2f6481f3..366bad58b 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -101,7 +101,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 @@ -265,4 +265,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 |