From eb53d600c911b91a65f73d467d682a085e8d8526 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 8 May 2012 10:39:42 +0000 Subject: [PATCH] Fixed that REST Uploads fail with fastcgi in 1.4-stable (#10832). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@9653 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/attachments_controller.rb | 2 +- app/models/attachment.rb | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 967032d92..cb975e85d 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -67,7 +67,7 @@ class AttachmentsController < ApplicationController return end - @attachment = Attachment.new(:file => request.body) + @attachment = Attachment.new(:file => request.raw_post) @attachment.author = User.current @attachment.filename = Redmine::Utils.random_hex(16) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index a6351da67..74669f569 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -110,10 +110,15 @@ class Attachment < ActiveRecord::Base logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)") md5 = Digest::MD5.new File.open(diskfile, "wb") do |f| - buffer = "" - while (buffer = @temp_file.read(8192)) - f.write(buffer) - md5.update(buffer) + if @temp_file.respond_to?(:read) + buffer = "" + while (buffer = @temp_file.read(8192)) + f.write(buffer) + md5.update(buffer) + end + else + f.write(@temp_file) + md5.update(@temp_file) end end self.digest = md5.hexdigest