Re: Using restclient for streaming multipart uploads

Archiloque <code@...>

you can enable some logging to see what is happening, like RestClient.log = 'STDOUT'


Le 2 nov. 2011 à 22:15, Anthony Rowlands a écrit :

Okay, I am trying this now:

def io.path
  return 'upload.lsz'

response =, {:payload => {
  :multipart => true,
  :content_type => 'multipart/form-data',
  :source => io
}}, {:cookies => {
    'JSESSIONID' => @sessionid

This seems to work, although my server isn't able to read the uploaded file contents. It does recognize the content-type as "multipart/form-data; boundary=993865", however... Not sure what happened. Do you know of a way to see what was actually written to the stream?


On Wed, Nov 2, 2011 at 3:08 PM, Anthony Rowlands <draftomatic@...> wrote:
Thanks for the reply!

Actually, #path is defined on StringIO already, but it always returns nil (see this doc). Can I override this method? Never done that before in Ruby...


On Wed, Nov 2, 2011 at 2:53 PM, Archiloque <code@...> wrote:
Shortest way would be to add a path method to your StringIO and RestClient will use it as a File

Please tell me if it works, this way I could add something about it in the code as it's not the first time the questions is asked.


Le 2 nov. 2011 à 21:42, Anthony Rowlands a écrit :

Hello RestClient list,

I am trying to use the RestClient library to do a multipart upload from a StringIO, not from a file. After scouring the code, it seems that this is not possible. It should be something like this (although this example is obviously wrong):

response =, :payload => {
        :multipart => true,
        :content_type => 'multipart/form-data',
        :source => myStringIO
      }, :headers => {
          :cookies => {
            'JSESSIONID' => @sessionid

In payload.rb, in Multipart.build_stream, v is the StringIO I passed to, and it leads to a call to create_file_field (StringIO seems to respond to :path even though this isn't documented in the rubydocs), but StringIO.path is always nil for me, which is causing problems:

Error: #<TypeError: can't convert nil into String>
C:/PROGRA~2/Google/GOOGLE~2/Plugins/Light Stanza/lib/restclient/payload.rb:202:in `basename'
C:/PROGRA~2/Google/GOOGLE~2/Plugins/Light Stanza/lib/restclient/payload.rb:202:in `create_file_field'
C:/PROGRA~2/Google/GOOGLE~2/Plugins/Light Stanza/lib/restclient/payload.rb:179:in `build_stream'

Can anyone help me with this? Is it possible to do a streaming multipart post from a StringIO?

Anthony R

Join to automatically receive all group messages.