I have to implement the curl POST request listed below in Ruby using Rest-Client so that I can upload a file to my server.
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'
I have tried the following -
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"})
This works okay as I get 200 response from the server. However, when I check for the uploaded file on my server it is corrupted.
Is this the right way to do multipart/form-data request using ruby?
I see there is the following in cURL request which is not accounted for in ruby request anywhere.
{"type":"formData"}
Do I need to do something extra for that?