【发布时间】:2019-05-28 04:16:14
【问题描述】:
我必须使用 Rest-Client 在 Ruby 中实现下面列出的 curl POST 请求,以便我可以将文件上传到我的服务器。
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Basic jhdsjhdshjhdshdhh' --header 'tenant-code:djdjhhsdsjhjsd=' {"type":"formData"} 'https://myserver.com/blobs/upload?fileName=some.ipa&groupId=098'
我已经尝试了以下 -
require 'rest-client'
require 'json'
payload = {
:multipart => true,
:file => File.new(path_to_file, 'rb')
}
response = RestClient.post("https://myserver.com/blobs/upload?fileName=some.ipa&groupId=098", payload, {accept: :json, 'tenant-code':"djdjhhsdsjhjsd=", 'Authorization': "Basic jhdsjhdshjhdshdhh"})
这可以正常工作,因为我从服务器收到 200 响应。但是,当我在我的服务器上检查上传的文件时,它已损坏。
这是使用 ruby 进行多部分/表单数据请求的正确方法吗?
我看到 cURL 请求中有以下内容,这在任何地方的 ruby 请求中都没有考虑。
{"type":"formData"}
我需要为此做些额外的事情吗?
【问题讨论】:
标签: ruby curl multipartform-data multipart rest-client