Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alfuken opened this issue Dec 8, 2013 · 2 comments
Open

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

alfuken opened this issue Dec 8, 2013 · 2 comments

Comments

@alfuken
Copy link

alfuken commented Dec 8, 2013

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
Copy link
Owner

taf2 commented Jan 2, 2014

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

Should work.?

@alfuken
Copy link
Author

alfuken commented Jan 2, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants