curl -u "my_username":"my_pass" \
-X POST \
-F "positive_examples=@/Users/abc/Downloads/tiger.zip" \
-F "negative_examples=@/Users/abc/Downloads/leopard.zip" \
-F "name=tiger" \
"http://localhost/api/v2/class"
最后,我可以将curl示例转换为Ruby,遵循ruby中的示例:
request = RestClient::Request.new(method: :post,
url: 'http://localhost/api/v2/class',
user: 'my_username',
password: 'my_pass',
payload: {multipart:true,
positive_examples:File.new("/Users/abc/Downloads/tiger.zip", 'rb'),
negative_examples:File.new("/Users/abc/Downloads/leopard.zip", 'rb')
name:'tiger'})
答案 0 :(得分:1)
RestClient::Request.execute method: :post,
url: 'http://localhost/api/v2/class',
user: 'my_username',
password: 'my_pass',
payload: {
multipart: true,
positive_examples: File.new('/Users/abc/Downloads/tiger.zip', 'rb'),
negative_examples: File.new('/Users/abc/Downloads/leopard.zip', 'rb'),
name: 'tiger',
}
只需阅读宝石的README。