Re: Using restclient for streaming multipart uploads


Archiloque <code@...>
 

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.

A.

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 = RestClient.post(url, :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 RestClient.post, 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?

Thanks,
Anthony R

Join {main@rest-client.groups.io to automatically receive all group messages.