Hi,
I am trying to upload local file to a rails-app through HTTP without multipart encoding. Doing so, I expect to get some performance boost on transferring large files. I am stucked Rails can't handle binary file upload, while it's OK with plain text files. Let me show a sample application skeleton:
config/routes.rb:
map.connect 'upload', :controller => 'application', :action => 'upload'
app/controllers/application.rb:
class ApplicationController < ActionController::Base def upload render :text => request.raw_post end end
Uploading plain file succeeds as following:
$ curl -v -T 42.txt http://localhost/upload * About to connect() to localhost port 80 * Trying 127.0.0.1... * connected * Connected to localhost (127.0.0.1) port 80
PUT /upload HTTP/1.1
User-Agent: curl/7.13.1 (powerpc-apple-darwin8.0) libcurl/7.13.1 OpenSSL/0.9.7i zlib/1.2.3 Host: localhost Pragma: no-cache Accept: */* Content-Length: 3 Expect: 100-continue
< HTTP/1.1 100 Continue < HTTP/1.1 200 OK < Date: Mon, 25 Sep 2006 18:51:11 GMT < Server: Mongrel 0.3.13.4 * Added cookie _session_id="b64a0dde1c857bd0d94ea95869f90294" for domain localhost, path /, expire 0 < Set-Cookie: _session_id=b64a0dde1c857bd0d94ea95869f90294; domain=localhost; path=/ < Status: 200 OK < Cache-Control: no-cache < Content-Type: text/html; charset=UTF-8 < Content-Length: 3 42 * Connection #0 to host localhost left intact * Closing connection #0
Uploading binary file fails like this:
$ curl -v -T photo1.jpg http://localhost/upload * About to connect() to localhost port 80 * Trying 127.0.0.1... * connected * Connected to localhost (127.0.0.1) port 80
PUT /upload HTTP/1.1
User-Agent: curl/7.13.1 (powerpc-apple-darwin8.0) libcurl/7.13.1 OpenSSL/0.9.7i zlib/1.2.3 Host: localhost Pragma: no-cache Accept: */* Content-Length: 60591 Expect: 100-continue
< HTTP/1.1 100 Continue < HTTP/1.1 200 OK < Date: Mon, 25 Sep 2006 18:52:15 GMT < Content-Type: text/html < Content-Length: 380 Status: 500 Internal Server Error Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <h1>Application error (Apache)</h1> <p>Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html</p> </body> * Connection #0 to host localhost left intact * Closing connection #0 </html>
I've written small cgi application to prove it might perform better, and it doesn't show any problem. So I would like to apply my idea to Rails application too. Comments are appreciated.