Many of the Telligent Evolution platform REST endpoints allow for for including a file attachment with your create or update requests. Examples include adding or updating a blog post, adding or updating a forum thread, adding or updating a media gallery file, and others. When reviewing the documentation for these endpoints you may have noticed a byte array FileData parameter, which is used for uploading the file, and wondered how you are supposed to format your request to set a value to that parameter. This is one of the most often asked questions I get about working with our REST APIs.
For attachments to be recognized by the Telligent Evolution REST API the content type of the request must be multipart/form-data. There are two suggested methods for including an attachment with your create or update requests documented in "How to upload a file - FileData". Check out that documentation for full examples.
The simplest way is to use WebClient.UploadFile(url, "POST", "path to your file") but there are limitations in its usage. WebClient.UploadFile() does not allow for also including values for other parameters in the post body. Instead you have to set all other request parameters in the querystring. This is fine when you only need to set a few additional values like Name and Description when creating a media file but you may run into trouble with the querystring length when you need to include many parameters or parameters that could have large amounts of content like when creating a blog post. In those situations you instead would want to use the other example described in the documentation, manually crafting your multipart form data request using boundaries to add your file's byte array and the additional request parameters. Again, see the documentation linked to above for both examples.
Note that you cannot use WebClient.UploadData() and WebClient.UploadValues() to include file attachments with the Telligent Evolution REST APIs. Those two methods automatically set the request's content type to application/x-www-form-urlencoded instead of multipart/form-data, which cannot be changed or overridden, and will not be recognized by the REST API as including a file attachment.