ServiceAPI upload file and associate with an existing record

I know it is possible to create a record and upload a file in a single ServiceAPI call PostFileWithRequest(), however, I would like to know if it’s possible to first upload a file using ServiceAPI and then associate it with an existing record? I found the blog with the section “Upload a file and create a new revision” where this exact requirement is covered, but there is a line of code I just can’t figure out:

var fileResponse = client.UploadFile(fi, System.Web.MimeMapping.GetMimeMapping(fi.Name));

The class TrimClient doesn’t have the method called “UploadFile” so I’m wondering how this “client” object gets instantiated? I have a feeling I am missing something obvious, so I apologize in advance.

Thanks in advance.

  • Verified Answer

    Although I’m still not clear about the line of code mentioned in my opening post, I think I solved the original problem. The requirement was to upload a file and associate it with an already existing record. I am able to do it by using the API PostFileWithRequest(). The trick is when creating the “Record” object to set the property “Uri” to the URI of the existing record. If the Record Type is setup to accept multiple revisions, this approach should work. So simple, yet it took me a day to figure it out. Hopefully it may help someone else from this community.