taf2 / curb

Ruby bindings for libcurl
Other
1.29k stars 229 forks source link

Can not use Curb as WebDav client for PUT requests. #177

Open alfuken opened 10 years ago

alfuken commented 10 years ago

Hi,

I'm writing a WebDav client using Curb for Yandex.Disk, everything was perfect untill I started to write PUT (file upload) functionality.

Please, see description here: http://api.yandex.com/disk/doc/dg/reference/put.xml

The thing is - I can NOT upload a file using Curl - it always have a length of 0 bytes after request.

Code I'm using:

url = 'https://webdav.yandex.ru/uploads/test.jpg'
file = '/Users/Bohdan/Desktop/test.jpg'
filename = 'test.jpg'
post_field = Curl::PostField.file(filename, file)
auth = "OAuth <auth token goes here, can provide my own for testing>"

c = Curl::Easy.new
c.url = url
c.multipart_form_post = true
c.headers["Authorization"] = auth
c.put_data = post_field
c.http :PUT

I've tried setting filename variable to different values - full path, relaive path, filename, nil, empty string; using POST; using post_body instead of put_data; with and without multipart. Zero luck.

So, my question is, HOW do I upload that damn file?..

taf2 commented 10 years ago

Curl.put(url) do|http| http.put_data = File.read(file) end

Should work.?

alfuken commented 10 years ago

With small files? Yes, it probably should. But try to upload 100Mb file, and you'll end up with memory eating monster, which is, obviously, not a best choice.

What's interesting: Curl itself, using command line, uploads files just fine, without cluttering up the memory. But using a system() call to upload a file is even worse solution than using a memory-eating-monster there.