Defect #10832

REST Uploads fail with fastcgi

Added by Jeffrey Clark over 5 years ago. Updated over 5 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:REST API
Target version:1.4.2
Resolution:Fixed Affected version:1.4.1

Description

Unable to upload attachments through REST API.

curl --data-binary "@README" -H "Content-Type: application/octet-stream" -X POST -u admin:test http://localhost/uploads.xml

Processing AttachmentsController#upload to xml (for 127.0.0.1 at 2012-05-04 11:52:53) [POST]
  Parameters: {"action"=>"upload", "controller"=>"attachments", "format"=>"xml"}

NoMethodError (undefined method `size' for #<Rack::RewindableInput:0x7ffb9b162fd0>):
  app/models/attachment.rb:78:in `file='
  app/controllers/attachments_controller.rb:70:in `new'
  app/controllers/attachments_controller.rb:70:in `upload'
  dispatch.fcgi:27

Rendering rescues/layout (internal_server_error)

rest-upload-fastcgi.patch Magnifier (716 Bytes) Jeffrey Clark, 2012-05-04 20:49

Associated revisions

Revision 9652
Added by Jean-Philippe Lang over 5 years ago

Fixed that REST Uploads fail with fastcgi (#10832).

Revision 9653
Added by Jean-Philippe Lang over 5 years ago

Fixed that REST Uploads fail with fastcgi in 1.4-stable (#10832).

History

#1 Updated by Jeffrey Clark over 5 years ago

Webrick appears to work fine. Perhaps a problem related to fastcgi.

#2 Updated by Jean-Philippe Lang over 5 years ago

  • Target version set to 1.4.2

I'm able to reproduce with apache+fastcgi.

#3 Updated by Jeffrey Clark over 5 years ago

Unfortunately the various Rack::Handler's don't handle input all the same way :(

#4 Updated by Jean-Philippe Lang over 5 years ago

Or maybe (untested):

Index: app/controllers/attachments_controller.rb
===================================================================
--- app/controllers/attachments_controller.rb    (revision 9616)
+++ app/controllers/attachments_controller.rb    (working copy)
@@ -67,7 +67,7 @@
       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)

#5 Updated by Jeffrey Clark over 5 years ago

Jean-Philippe Lang wrote:

Or maybe (untested):

Nope :(

NoMethodError (undefined method `read' for #<String:0x7f191b1fbae0>):
  app/models/attachment.rb:114:in `files_to_final_location'
  app/models/attachment.rb:112:in `open'
  app/models/attachment.rb:112:in `files_to_final_location'
  app/controllers/attachments_controller.rb:74:in `upload'
  dispatch.fcgi:27

#6 Updated by Jean-Philippe Lang over 5 years ago

Jeffrey Clark wrote:

Nope :(

The patch should work after r9630.

#7 Updated by Jean-Philippe Lang over 5 years ago

  • Subject changed from REST Uploads fail to REST Uploads fail with fastcgi
  • Assignee set to Jean-Philippe Lang

#8 Updated by Jean-Philippe Lang over 5 years ago

  • Status changed from New to Closed
  • Resolution set to Fixed

Fixed in 1.4-stable (r9653) and trunk (r9652). Tested with apache2+fcgid.

Also available in: Atom PDF