Skip to main content
Question

I am trying to upload file with'rest-client' gems.

  • May 22, 2025
  • 5 replies
  • 14 views

Forum|alt.badge.img

I am trying to upload file with'rest-client' gems.  I have tried but no luck. Here the code I tried so far.

content_type = MIME::Types.type_for('/home/vagrant/mukesh.txt').first.content_type

headers = {
"Authorization"=> "Bearer ",
"Content-Type"=> content_type
}

payload = {
"attributes"=> {"name"=>"mukesh.txt", "parent"=>{"id"=>"0"}},
"file"=> File.new('/home/vagrant/mukesh.txt', 'rb'),
"multipart"=> true
}
response = RestClient::Request.execute(:method=> :post,:url=>"https://upload.box.com/api/2.0/files/content",:payload=>payload , :headers=> headers)

It is giving, 405 method not allowed errors.  Can somebody help me?

5 replies

Forum|alt.badge.img

 Have you seen the Box Ruby SDK? Here is the method signature to upload a file with the Ruby SDK.


Forum|alt.badge.img

Thanks for reply 🙂 
Yah, it worked with the boxr gem.  I had figured it out before. 


Forum|alt.badge.img

Did it only work with the boxr gem, or were you able to get it working with the RestClient gem as well?


Forum|alt.badge.img

Also Murtza, I might ask if there is anything wrong or that can be adjusted to the RestClient call to make it work? This should be a straightforward HTTP task.


Forum|alt.badge.img

I won't able to upload a file from rest-client. Surprising, It does work with the postman, though postman externally using rest call only.  I think something wrong with the code that I have written. 
Using Boxer (Ruby gem) easy and fast.  It does solve my problem so I completed my task with boxr gem.