如何使用rest客户端将cURL多部分/表单数据POST请求转换为ruby请求?

如何使用rest客户端将cURL多部分/表单数据POST请求转换为ruby请求?,ruby,curl,multipartform-data,multipart,rest-client,Ruby,Curl,Multipartform Data,Multipart,Rest Client,我必须使用Rest客户机在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"

我必须使用Rest客户机在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"}

我需要为此做些额外的事情吗?

我通过将请求更改为以下内容来解决我的特定案例(我需要将IPA文件上载到我的企业应用商店):-

require 'rest-client'
require 'json'

response = RestClient::Request.execute(
  :url => "https://myserver.com/blobs/upload?fileName=some.ipa&groupId=098",
  :method => :post,
  :headers => {
    'Authorization' => "Basic jhdsjhdshjhdshdhh",
    'tenant-code' => "djdjhhsdsjhjsd=",
    'Accept' => 'application/json',
    'Content-Type' => 'application/octet-stream',
    'Expect' => '100-continue'
  },
  :payload => File.open(path_to_file, "rb")
)
基本上,内容类型需要是八位字节流,Expect头也需要设置

希望它能帮助那些来找这种东西的人