Got the error File type is not supported when uploading a file in ruby on rails

133 Views Asked by At
 url = URI("https://api.podium.com/v4/messages/attachment")
      https = Net::HTTP.new(url.host, url.port)
      https.use_ssl = true
      request = Net::HTTP::Post.new(url)
      request["Content-Type"] = "multipart/form-data"
      request["Authorization"] = "Bearer #{access_token}"
      form_data = [["attachment",File.open('D:\proj\v5\ap\fl\Screenshot (1).png')],['data', "#{request_data}"]]
      request.set_form(form_data, 'multipart/form-data')
      response = https.request(request)
      response_body = JSON.parse(response.body)
      if response.code == '200' || response.code == '201'
          return response_body,'success'
      else
           return response_body,"#{response.message}"
      end
      rescue Exception => ex
        return ex,'Exception'
     end

** When i am sending the request i got the error like

{"code"=>"invalid_request_values", "message"=>"File type is not supported.", "moreInfo"=>"https://docs.podium.com/docs/errors#invalid_request_values"} **

1

There are 1 best solutions below

1
Ghouse Mohamed On

Here are a couple of things you could try:

  1. The podium documentation says that the images cannot be above 5mb in size. You can verify if this is the case.

https://help.podium.com/hc/en-us/articles/360039896873-Sending-Messages#Attach%20media%20to%20a%20message

  1. I noticed the code snippet you've shared does set have this line as mentioned in their documentation here https://docs.podium.com/reference/messagesend_with_attachment
request["accept"] = 'application/json'

Maybe adding this header might fix it for you, as you are saying that it is working for you in Postman but not in Ruby.

  1. Try uploading the file from the API Doc reference page itself and check out the code sample they provide there. There are some differences in the code sample you've shared, and the one that podium shows in their doc.