Been using rest-client for some time now, but new to Airborne. The snag I've hit is that I can't seem to get multi-part post for file upload working with Airborne. I wind up with a bad request 'Missing start boundary' My Airborne POST looks like this:
before :all do
fyle = File.new("e:/some-file.jpg", 'rb')
body = {:profile => "KonflictME", :file => fyle, :multipart => true}
post "/uploads", body, { :content_type => 'multipart/form-data' }
end
My working example using rest-client looks like this:
fyle = File.new("e:/some-file.jpg, 'rb')
resp = RestClient.post base_path_api << "uploads",
{:profile => "KonflictME", :file => fyle, :multipart => true},
{:authorization => "myTokenString}
Not a lot of difference between the two, shouldn't be since rest-client is used under the hood for Airborne. For Airborne, base_url and headers are setup in config (spec_helper.rb).
Has anyone else tried a multi-part post with Airborne? Uploads are only a small part of my test suite and I have a non-Airborne solution (just use rest-client directly for these tests), but would like to keep things simple for the rest of team.
airborne framework is based on restclient, and in the source code there is a line in lib/airborne/rest_client_requester.rb:
request_body = request_body.to_json if options[:body].is_a?(Hash)
which means every body you have defined will be transfered into json, and as a parameter in follow line:
RestClient.send(method, get_url(url), request_body, headers)
But in restclient, you don't need to consider the pattern of body whether you want to post a json or upload a file. If you want to upload a file you can change the above code to:
request_body = request_body.to_json if options[:body].is_a?(Hash) && options[:body].to_json["file"].nil?
to check if body you defined contains a file. I have made this change in my recent project.
Hope this will help you.