Upload Files to FM 17 Data API with ruby

Thanks Monkeybread!

I sent the post request to a different app and saw that the library i used Ruby/HTTParty didnt send the body because multipart is not supported.
I switched to Faraday and now it works well.

For the case it may help someone, here is the code

url = "https://rocky.datenbank-hosting.com/fmi/data/v1/databases/rocky/layouts/#{layout}/records/#{fm_id}/containers/#{container_field_name}/1"
 ur = URI.parse(url)
      conn = Faraday.new(url, headers: { authorization: "Bearer #{@token}" }) do |f|
        f.request :multipart
        f.request :url_encoded
        f.adapter :net_http
      end
      payload = { :upload => Faraday::UploadIO.new(file_path, 'image/jpeg') }
      response = conn.post(ur.path, payload)

I spent days with this!
Gems i tried that are not working for me:

  • FmRest (Beezwax) => could not create any record, and i found it more helpful to go more to the root-libraries
  • directly CURL inside ruby => that is too much root :slight_smile: possible, but at the end you want to have a wrapper, that is more convenient
  • Multipart-Post => workes fine, but not for FileMaker
  • and some others :slight_smile:
3 Likes