Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6167557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:32:02+00:00 2026-05-23T22:32:02+00:00

I’m trying to post multipart content (a file and some strings) to a Sinatra

  • 0

I’m trying to post multipart content (a file and some strings) to a Sinatra server on localhost using a java client. It seems the server doesn’t like the POST message. The stack trace is:

ERROR NoMethodError: undefined method `rewind' for "hi":String
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:581:in`block in parse_multipart'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:499:in`loop'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:499:in`parse_multipart'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/request.rb:270:in `parse_multipart'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/request.rb:148:in `POST'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/methodoverride.rb:15:in `call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `block in call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1303:in `synchronize'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/content_length.rb:13:in `call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/handler/webrick.rb:52:in `service'
        D:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
        D:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
        D:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

My server prints out the params in the post message. Here’s what they are for my java client:

Content-Disposition: form-data; name="file"; filename="fff.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
#<File:0xedbc10>
Content-Disposition: form-data; name="jjj"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
hi

The java code I’m using is:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:4567/upload");
File file = new File("D:/My Documents/My Desktop/fff.jpg");     
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpeg");
mpEntity.addPart("file", cbFile);
ContentBody stringBody = new StringBody("hi", Charset.forName("UTF8"));
mpEntity.addPart("jjj", stringBody);
httppost.setEntity(mpEntity);
HttpResponse response = httpclient.execute(httppost);

So it seems Rack doesn’t like dealing with content type when the content type is a string. When I set the content_type variable inside rack/utils.rb to nil when the param is not a file everything works fine. Is this intentional or should it be submitted as a bug?
See also http://blogs.oracle.com/mandy/entry/rack_and_content_type_for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:32:02+00:00Added an answer on May 23, 2026 at 10:32 pm

    This is a Rack bug, but you can avoid it in java by doing your upload like this:

    HttpPost httpost = new HttpPost(
                    "http://192.168.140.17:3000/ze/api/documents.xml");
    MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
    entity.addPart( "folder_id", new StringBody("3", "multipart/form-data", Charset.defaultCharset()) );//f2
    entity.addPart( "labels", new StringBody("1,3,4", "form-data", Charset.defaultCharset() ) );
    entity.addPart( "uploaded_data", new FileBody(this.file, filename, "application/pdf", null) );
    httpost.setEntity(entity);
    

    The catch is creating the MultipartEntity with HttpMultipartMode.BROWSER_COMPATIBLE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.