mulitpart upload from java not working with rails 3.0.9 & 3.0.10 #2559

Closed
magegu opened this Issue Aug 17, 2011 · 1 comment

Projects

None yet

1 participant

@magegu

hi guys, im using the Apache HttpClient 4.1.1 + httpMime Lib 4.1.1 on Client Side to upload a file and some textual data:

CountingMultipartEntity mpEntity = new CountingMultipartEntity(this);
File file = new File(getRealPathFromURI(Uri.parse(local_uri)));
ContentBody cbFile = new FileBody(file, "image/jpeg");

mpEntity.addPart("artifact[binary_payload]", cbFile);
mpEntity.addPart("artifact[description]", new StringBody("test", Charset.forName("UTF-8")));

HttpPost post = new HttpPost(url);
post.setEntity(mpEntity);

HttpResponse response = mHttpClient.execute(post);

I'll always get this error using 3.0.9 and 3.0.10

Error during failsafe response: ActionView::Template::Error
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/activesupport-3.0.10/lib/active_support/whiny_nil.rb:48:in `method_missing'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_dispatch/http/parameters.rb:10:in `parameters'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb:3:in `___sers_mage__rvm_gems_ruby_______p____ssp_gems_actionpack________lib_action_dispatch_middleware_templates_rescues_diagnostics_erb___1898302173402227341_2168760180_363515282859101696'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_view/template.rb:135:in `block in render'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/activesupport-3.0.10/lib/active_support/notifications.rb:54:in `instrument'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_view/template.rb:127:in `render'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:59:in `block in _render_template'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in `block in instrument'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/activesupport-3.0.10/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in `instrument'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:56:in `_render_template'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:26:in `render'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_dispatch/middleware/show_exceptions.rb:88:in `rescue_action_locally'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_dispatch/middleware/show_exceptions.rb:68:in `render_exception'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_dispatch/middleware/show_exceptions.rb:59:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/railties-3.0.10/lib/rails/rack/logger.rb:13:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/rack-1.2.3/lib/rack/runtime.rb:17:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/activesupport-3.0.10/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/rack-1.2.3/lib/rack/lock.rb:11:in `block in call'
  <internal:prelude>:10:in `synchronize'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/rack-1.2.3/lib/rack/lock.rb:11:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/actionpack-3.0.10/lib/action_dispatch/middleware/static.rb:30:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/railties-3.0.10/lib/rails/application.rb:168:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/railties-3.0.10/lib/rails/application.rb:77:in `method_missing'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/railties-3.0.10/lib/rails/rack/log_tailer.rb:14:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/rack-1.2.3/lib/rack/content_length.rb:13:in `call'
  /Users/mage/.rvm/gems/ruby-1.9.2-p136@ssp/gems/rack-1.2.3/lib/rack/handler/webrick.rb:52:in `service'
  /Users/mage/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /Users/mage/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /Users/mage/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

09:51:55 Started POST "/compass/projects/4e247634a58e230f4700001c/artifacts.json?auth_token=2f2m2u5ymydXOFjAiblT" for 192.168.1.148 at 2011-08-17 09:51:55 +0200

09:51:55 NoMethodError (undefined method `rewind' for "test":String):

the equivalent HTML form works fine:

<form accept-charset="UTF-8" action="/compass/projects/4e247634a58e230f4700001c/artifacts" enctype="multipart/form-data" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="ksATRdteazWPOwZx2OfPaPXSpQVNSvPqAOzosT5g/Jg=" /></div> 
  <label for="description">description:</label><input type="text" id="description" name="artifact[description]"/> 
  <label for="payload_uri">payload (uri/upload):</label><input type="text" name="artifact[payload_uri]"/> 
  <input type="file" name="artifact[binary_payload]"/> 
  <input id="submit" type="submit" name="submit" value="ok"></input> 
</form> 

when i'm using php from the java code, everything works fine:

<pre><? print_r($_FILES); ?> </pre>

Array
(
    [artifact] => Array
        (
            [name] => Array
                (
                    [binary_payload] => IMG_4560b.jpg
                )

            [type] => Array
                (
                    [binary_payload] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [binary_payload] => /tmp/phpytXsYb
                )

            [error] => Array
                (
                    [binary_payload] => 0
                )

            [size] => Array
                (
                    [binary_payload] => 146932
                )

        )

i found some hints on some websites that this could be a rails issue - so i'm now trying to get some feedback here :)

@magegu

i still don't know whats the different, but i head to use

HttpMultipartMode.BROWSER_COMPATIBLE
@magegu magegu closed this Aug 21, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment