I have an HTTP API to which I can transfer files as below:
curl -T /my/file/path http://server.name/api/file.in
How can I translate this into Ruby code?
I have an HTTP API to which I can transfer files as below:
curl -T /my/file/path http://server.name/api/file.in
How can I translate this into Ruby code?
Looks like a duplicate of this question, the accepted answer here will probably help you out: Ruby: How to post a file via HTTP as multipart/form-data?
Using PUT and rest-client
Per the comments below, I realized the curl -T command appears to be doing a HTTP PUT with the data parameter being the binary data from the file. Using the rest-client ruby gem I believe the following code, possibly with minor variation, -should- work for you:
require 'rest-client'
RestClient.put "http://server.name/api/file.in", File.read("/my/file/path")
You may need to set the content-type header for certain types of files, though curl -T didn't appear to be doing that. In that case, you'd do:
RestClient.put "http://server.name/api/file.in", File.read("/my/file/path"), :content_type => 'text/plain'
Source: https://github.com/rest-client/rest-client/blob/master/lib/restclient.rb comments on RestClient module.