Ruby - Net::HTTP gives no multipart boundary was found error with multipart/form-data

292 Views Asked by At

I am trying to consume an multipart/form-data API with Ruby - Net::HTTP but it gives below error

{"error":{"code":"INTERNAL_SERVER_ERROR","message":"Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: 
the request was rejected because no multipart boundary was found","data":{}}}

cURL is working but Ruby - Net::HTTP request is not working, below is the request -

require "uri"
require "net/http"

url = URI("[base_url]/rest/v1/companies/11/notifications/email-with-attachment?content_type=static")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["client"] = "mobi"
form_data = [
  ['email_data', '{"message":"Test\\tMessage","type":"mobi","priority":"LOW","email":{"to_email_ids":["[email protected]"],"cc_email_ids":[],"bcc_email_ids":[],"from_email_id":"[email protected]","subject":"subject - test email","attachment":[]}}'],
  ['attachment', File.open('/Users/dummy/Desktop/Screenshot 2022-11-07 at 10.45.11 AM.png')]
]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body

Any help is appreciated. Thanks

0

There are 0 best solutions below