Sending the parent object to the Box File Upload API in Ruby on Rails

I'm attempting to use the Box File Upload API to send a file to 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:

Here is their curl example:

curl \
-H "Authorization: Bearer ACCESS_TOKEN" -X POST \
-F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
-F file=@myfile.jpg

I'm attempting to use RailsClient to do this in my app and here are the two ways I've tried:,{ :name => "randompdf.pdf", :parent => {:id => 0}, :myfile => file }, { :Authorization => "Bearer #{NEW_TOKEN}" })


@parent = = 0,{ :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.

1 answer

  • answered 2018-01-11 20:57 marginalchaos

    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}"})