Date   

Re: RestClient and SSL stores/default paths

Cyril Rohr <cyril.rohr@...>
 

On Apr 12, 2012, at 9:57 AM, David Ljung Madison wrote:

I don't know much about SSL, but I'm trying to use RestClient to
connect to my SSL server. I tried the simple RestClient example
I found and added this to Resource.new:

:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("gd_intermediate.pem")),
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
If you want to verify server certificates, you need to pass the
path to a Certification Authority (CA) file with the :ssl_ca_file
I tried that with:

:ssl_ca_file => "/etc/ssl/certs/Go_Daddy_Class_2_CA.pem",

But that didn't work either. What are the ssl settings I give to
RestClient and where do I get the certs?
Actually, unless you're doing mutual SSL authentication with the server, you should not pass an :ssl_client_cert option. Is your server live somewhere so that we can test?

Cyril
--
http://crohr.me


Re: RestClient and SSL stores/default paths

David Ljung Madison <librelist.com@...>
 

I don't know much about SSL, but I'm trying to use RestClient to
connect to my SSL server. I tried the simple RestClient example
I found and added this to Resource.new:

:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("gd_intermediate.pem")),
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
If you want to verify server certificates, you need to pass the
path to a Certification Authority (CA) file with the :ssl_ca_file
I tried that with:

:ssl_ca_file => "/etc/ssl/certs/Go_Daddy_Class_2_CA.pem",

But that didn't work either. What are the ssl settings I give to
RestClient and where do I get the certs?

Dave

-----------------------------------------------------------------------------
Dave Ljung Madison http://GetDave.com/ 415.341.5555
------- Walking on water and developing software from a specification -------
are easy if both are frozen. - Edward V. Berard


Re: RestClient and SSL stores/default paths

Cyril Rohr <cyril.rohr@...>
 

Hello,

On Apr 12, 2012, at 2:26 AM, David Ljung Madison wrote:

I don't know much about SSL, but I'm trying to use RestClient to
connect to my SSL server. I tried the simple RestClient example
I found and added this to Resource.new:

:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("gd_intermediate.pem")),
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
If you want to verify server certificates, you need to pass the path to a Certification Authority (CA) file with the :ssl_ca_file option. This file should contain at least the certificate of the CA that signed the server certificate you want to verify (in your case, GoDaddy's).

That being said, it would be nice to support a store path option so that it's easier to verify certificates delivered by common CAs.

Cyril
--
http://crohr.me


RestClient and SSL stores/default paths

David Ljung Madison <librelist.com@...>
 

I don't know much about SSL, but I'm trying to use RestClient to
connect to my SSL server. I tried the simple RestClient example
I found and added this to Resource.new:

:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("gd_intermediate.pem")),
:verify_ssl => OpenSSL::SSL::VERIFY_PEER

(Our server's cert is signed by GoDaddy)

This did not work (SSL verify failed) - everything works fine with
verify_ssl turned off.


I found a Net::HTTP example that worked fine by using an OpenSSL store:

net = Net::HTTP.new("custman.iceleropoc.net", 8443)
net.use_ssl = true
net.verify_mode = OpenSSL::SSL::VERIFY_PEER
store = OpenSSL::X509::Store.new
store.set_default_paths # This is required!
net.cert_store = store

RestClient doesn't seem to have a way to use the store, or to set
the default paths. If I understood x509/SSL better I might understand
what I'm doing wrong.

I tried adding the store with default paths to net in request.rb and
then RestClient started to work.

Is RestClient missing this feature, or is there some other way to do
what I'm trying to do?

Dave

---------------------------------------------------------------------------
Dave Ljung Madison http://GetDave.com/ 415.341.5555
--- "Debugging is twice as hard as writing the code in the first place. ---
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan


Re: examples

Tom Allison <tom@...>
 

No windows.
But I do have a HTTP proxy that works similarly.

- T (iPhone)

On Feb 29, 2012, at 12:16, Charles S van der Linden <sqapro@...> wrote:

It only works on Windows as far as I know, so if you are on another
platform you'd need to find a similar tool.

I use it a lot when developing steps. in cucumber that use rest_client
I have a $test_debug_mode variable I set based on an environment
variable, and then in env.rb I have

RestClient.proxy = 'http://127.0.0.1:8888/' if $test_debug_mode

which tells rest client to pump everything through fiddler, it allows
me to easily see exactly what was sent and received, (reformatted
thanks to fiddler to be super easy to make sense of)



On Tue, Feb 28, 2012 at 5:28 PM, Tom Allison <tom@...> wrote:
Fiddler2... I'll check it out. Thank you.

- T (iPhone)

On Feb 28, 2012, at 19:11, Charles S van der Linden <sqapro@...> wrote:

IF you are unsure or don't have a clear spec, I would use something
like fiddler2 to observe 'normal' interaction by making manual
requests using a browser, or browser with a rest-testing plugin. See
how the session ID is passed back and forth. Is it a header value,
part of the querystring or something else? there's more than one way
to skin that cat.

Then emulate what the site expects. it's easy to specify header
values or querystring values

On Tue, Feb 28, 2012 at 12:03 PM, Tom Allison <tom@...> wrote:
Are there any examples of how this can be used with a session_id based
authentication?


Re: examples

Charles S van der Linden <sqapro@...>
 

It only works on Windows as far as I know, so if you are on another
platform you'd need to find a similar tool.

I use it a lot when developing steps. in cucumber that use rest_client
I have a $test_debug_mode variable I set based on an environment
variable, and then in env.rb I have

RestClient.proxy = 'http://127.0.0.1:8888/' if $test_debug_mode

which tells rest client to pump everything through fiddler, it allows
me to easily see exactly what was sent and received, (reformatted
thanks to fiddler to be super easy to make sense of)

On Tue, Feb 28, 2012 at 5:28 PM, Tom Allison <tom@...> wrote:
Fiddler2...  I'll check it out. Thank you.

- T (iPhone)

On Feb 28, 2012, at 19:11, Charles S van der Linden <sqapro@...> wrote:

IF you are unsure or don't have a clear spec, I would use something
like fiddler2 to observe 'normal' interaction by making manual
requests using a browser, or browser with a rest-testing plugin.  See
how the session ID is passed back and forth.  Is it a header value,
part of the querystring or something else?  there's more than one way
to skin that cat.

Then emulate what the site expects.  it's easy to specify header
values or querystring values

On Tue, Feb 28, 2012 at 12:03 PM, Tom Allison <tom@...> wrote:
Are there any examples of how this can be used with a session_id based
authentication?


Re: examples

Tom Allison <tom@...>
 

Fiddler2... I'll check it out. Thank you.

- T (iPhone)

On Feb 28, 2012, at 19:11, Charles S van der Linden <sqapro@...> wrote:

IF you are unsure or don't have a clear spec, I would use something
like fiddler2 to observe 'normal' interaction by making manual
requests using a browser, or browser with a rest-testing plugin. See
how the session ID is passed back and forth. Is it a header value,
part of the querystring or something else? there's more than one way
to skin that cat.

Then emulate what the site expects. it's easy to specify header
values or querystring values

On Tue, Feb 28, 2012 at 12:03 PM, Tom Allison <tom@...> wrote:
Are there any examples of how this can be used with a session_id based
authentication?


Re: examples

Charles S van der Linden <sqapro@...>
 

IF you are unsure or don't have a clear spec, I would use something
like fiddler2 to observe 'normal' interaction by making manual
requests using a browser, or browser with a rest-testing plugin. See
how the session ID is passed back and forth. Is it a header value,
part of the querystring or something else? there's more than one way
to skin that cat.

Then emulate what the site expects. it's easy to specify header
values or querystring values

On Tue, Feb 28, 2012 at 12:03 PM, Tom Allison <tom@...> wrote:
Are there any examples of how this can be used with a session_id based
authentication?


examples

Tom Allison <tom@...>
 

Are there any examples of how this can be used with a session_id based authentication?


Fork

David Ljung Madison <librelist.com@...>
 

I've created a very simple fork of rest-client that allows
per-resource proxy settings:

resource = RestClient::Resource.new(url, :proxy => auth.proxy)
response = resource.get()

I needed this because I am using RestClient in threads to access many
resources, some proxied, some not.

I put the code up as a fork on github, not sure if that's the proper
way to put it up for inclusion in the project, but the repo is here:

https://github.com/Daveola/rest-client

Along those lines - does anyone know about how thread-safe RestClient is?

Dave

---------------------------------------------------------------------------
Dave Ljung Madison http://GetDave.com/ 415.341.5555
--- "Debugging is twice as hard as writing the code in the first place. ---
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan


Re: Using restclient for streaming multipart uploads

Anthony Rowlands <draftomatic@...>
 

I ran out of time myself, so hacked something together that is good enough for now with a straight stream instead of a multipart stream.

If you get ever find time to use StringIO with multipart, let me know, I'd be happy to have the solution since I pretty much spent all day today trying to get it working. =D This will suffice for the time being...

Thank you very much for your help!

Anthony R


On Wed, Nov 2, 2011 at 4:56 PM, Archiloque <code@...> wrote:
I think so but unfortunately I don't have tile now to retrieve it, for a quickfix you could write the StringIO to a TempFile and use it as a parameter

A.


Le 2 nov. 2011 à 23:44, Anthony Rowlands a écrit :

I just printed the raw request body on my server, and it is empty... The correct headers were sent, but there is nothing in the body.

Are you sure RestClient can handle this? You said it's not the first time someone has tried... Has anyone else gotten it to work? 

Anthony

On Wed, Nov 2, 2011 at 4:30 PM, Archiloque <code@...> wrote:

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

Logging is showing this:

RestClient.post "http://localhost:8080/LightStanza/lsz-upload?projectKey=20", 30929 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"30929", "Content-Type"=>"multipart/form-data; boundary=89514", "Cookie"=>"JSESSIONID=2DC341E5B9A96F8AE9DDB94267BA47F4"

Does this look okay to you? 30kb sounds about right for the data I'm testing with. It could be server-side problem at this point, but without seeing the actual stream it's hard to tell.

Also, do you see a problem with generating a random number for the file boundary? Seems like it's possible that this exact number would show up in the file content, which goes against the RFC.

seems difficult as you seem to have tried several time, you could perhaps use a simple logging proxy en your machine to see what exactly happen ?

A.





Re: Using restclient for streaming multipart uploads

Archiloque <code@...>
 

I think so but unfortunately I don't have tile now to retrieve it, for a quickfix you could write the StringIO to a TempFile and use it as a parameter

A.


Le 2 nov. 2011 à 23:44, Anthony Rowlands a écrit :

I just printed the raw request body on my server, and it is empty... The correct headers were sent, but there is nothing in the body.

Are you sure RestClient can handle this? You said it's not the first time someone has tried... Has anyone else gotten it to work? 

Anthony

On Wed, Nov 2, 2011 at 4:30 PM, Archiloque <code@...> wrote:

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

Logging is showing this:

RestClient.post "http://localhost:8080/LightStanza/lsz-upload?projectKey=20", 30929 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"30929", "Content-Type"=>"multipart/form-data; boundary=89514", "Cookie"=>"JSESSIONID=2DC341E5B9A96F8AE9DDB94267BA47F4"

Does this look okay to you? 30kb sounds about right for the data I'm testing with. It could be server-side problem at this point, but without seeing the actual stream it's hard to tell.

Also, do you see a problem with generating a random number for the file boundary? Seems like it's possible that this exact number would show up in the file content, which goes against the RFC.

seems difficult as you seem to have tried several time, you could perhaps use a simple logging proxy en your machine to see what exactly happen ?

A.




Re: Using restclient for streaming multipart uploads

Anthony Rowlands <draftomatic@...>
 

I just printed the raw request body on my server, and it is empty... The correct headers were sent, but there is nothing in the body.

Are you sure RestClient can handle this? You said it's not the first time someone has tried... Has anyone else gotten it to work? 

Anthony


On Wed, Nov 2, 2011 at 4:30 PM, Archiloque <code@...> wrote:

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

Logging is showing this:

RestClient.post "http://localhost:8080/LightStanza/lsz-upload?projectKey=20", 30929 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"30929", "Content-Type"=>"multipart/form-data; boundary=89514", "Cookie"=>"JSESSIONID=2DC341E5B9A96F8AE9DDB94267BA47F4"

Does this look okay to you? 30kb sounds about right for the data I'm testing with. It could be server-side problem at this point, but without seeing the actual stream it's hard to tell.

Also, do you see a problem with generating a random number for the file boundary? Seems like it's possible that this exact number would show up in the file content, which goes against the RFC.

seems difficult as you seem to have tried several time, you could perhaps use a simple logging proxy en your machine to see what exactly happen ?

A.



Re: Using restclient for streaming multipart uploads

Archiloque <code@...>
 


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

Logging is showing this:

RestClient.post "http://localhost:8080/LightStanza/lsz-upload?projectKey=20", 30929 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"30929", "Content-Type"=>"multipart/form-data; boundary=89514", "Cookie"=>"JSESSIONID=2DC341E5B9A96F8AE9DDB94267BA47F4"

Does this look okay to you? 30kb sounds about right for the data I'm testing with. It could be server-side problem at this point, but without seeing the actual stream it's hard to tell.

Also, do you see a problem with generating a random number for the file boundary? Seems like it's possible that this exact number would show up in the file content, which goes against the RFC.

seems difficult as you seem to have tried several time, you could perhaps use a simple logging proxy en your machine to see what exactly happen ?

A.


Re: Using restclient for streaming multipart uploads

Anthony Rowlands <draftomatic@...>
 

Logging is showing this:

RestClient.post "http://localhost:8080/LightStanza/lsz-upload?projectKey=20", 30929 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"30929", "Content-Type"=>"multipart/form-data; boundary=89514", "Cookie"=>"JSESSIONID=2DC341E5B9A96F8AE9DDB94267BA47F4"

Does this look okay to you? 30kb sounds about right for the data I'm testing with. It could be server-side problem at this point, but without seeing the actual stream it's hard to tell.

Also, do you see a problem with generating a random number for the file boundary? Seems like it's possible that this exact number would show up in the file content, which goes against the RFC.

Thanks again,
Anthony

On Wed, Nov 2, 2011 at 3:23 PM, Archiloque <code@...> wrote:
you can enable some logging to see what is happening, like RestClient.log = 'STDOUT'

A.


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

Okay, I am trying this now:

def io.path
  return 'upload.lsz'
end

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

Anthony

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...

Anthony


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.

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






Unsubscribe

Keith Bennett <keithrbennett@...>
 

Hi, I hope you all don't get this message -- the Github page tells how
to subscribe, but not how to unsubscribe, and I don't think I saved
the initial email message from the list.

If you get this, would you please tell me how to unsubscribe? I'm no
longer working on the project that uses rest-client.

Thanks,
Keith


Re: Using restclient for streaming multipart uploads

Archiloque <code@...>
 

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

A.


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

Okay, I am trying this now:

def io.path
  return 'upload.lsz'
end

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

Anthony

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...

Anthony


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.

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





Re: Using restclient for streaming multipart uploads

Anthony Rowlands <draftomatic@...>
 

Okay, I am trying this now:

def io.path
  return 'upload.lsz'
end

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

Anthony

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...

Anthony


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.

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




Re: Using restclient for streaming multipart uploads

Anthony Rowlands <draftomatic@...>
 

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...

Anthony


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.

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



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

41 - 60 of 314