Reputation: 21
I'm attempting to use the Box File Upload API to send a file to Box.com from a Ruby on Rails application. However, I keep getting a bad request response that says parent is a missing parameter.
Here is their documentation: https://developer.box.com/v2.0/reference#upload-a-file
Here is their curl example:
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer ACCESS_TOKEN" -X POST \
-F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
-F [email protected]
I'm attempting to use RailsClient to do this in my app and here are the two ways I've tried:
RestClient.post(BASE_CONTENT_URL,{ :name => "randompdf.pdf", :parent => {:id => 0}, :myfile => file }, { :Authorization => "Bearer #{NEW_TOKEN}" })
&
@parent = Struct.new(:id)
@parent.id = 0
RestClient.post(BASE_CONTENT_URL,{ :name => "randompdf.pdf", :parent => @parent, :myfile => file }, { :Authorization => "Bearer #{NEW_TOKEN}" })
I get the same error attempting to do it via Postman as well. Box's Community Forum and Support resources haven't gotten back to me so I'm a little lost.
Upvotes: 0
Views: 172
Reputation: 21
attributes = {name: #{unique_name}, parent: { id: 0 }}
box_response = RestClient::Request.execute(method: :post,
url: BASE_UPLOAD_URL + "/content",
payload: { attributes: attributes.to_json,
file: file},
headers: {Authorization: "Bearer #{NEW_TOKEN}"})
Upvotes: 0