Can not use Curb as WebDav client for PUT requests.
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?..
Curl.put(url) do|http| http.put_data = File.read(file) end
Should work.?
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.