Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i add binary-data to curb POST

Tags:

ruby

curb

I'm trying to do the following POST to Parse Cloud using the Curb gem

curl -X POST \
  -H "X-Parse-Application-Id: PARSE_APP_ID" \
  -H "X-Parse-REST-API-Key: PARSE_API_KEY" \
  -H "Content-Type: image/jpeg" \
  --data-binary '@myPicture.jpg' \
  https://api.parse.com/1/files/pic.jpg

with this:

curl = Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")
curl.multipart_form_post = true
curl.headers["X-Parse-Application-Id"] = PARSE_APP_ID
curl.headers["X-Parse-REST-API-Key"] = PARSE_API_KEY
curl.headers["Content-Type"] = "image/jpg"
res = curl.http_post(Curl::PostField.file('file', image.path))

Upload goes through with a 201, but it doesn't seem like the file makes it up to the server correctly.

like image 906
haider Avatar asked Sep 14 '12 23:09

haider


1 Answers

Figured it out:

curl = Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")
curl.headers["X-Parse-Application-Id"] = PARSE_APP_ID
curl.headers["X-Parse-REST-API-Key"] = PARSE_API_KEY
curl.headers["Content-Type"] = "image/jpeg"
data = File.read('/Users/haider/Pictures/lion.jpg')
curl.post_body=data
curl.http_post
puts curl.body_str
like image 115
haider Avatar answered Sep 29 '22 21:09

haider