var client = new RestClient("https://api.example.com"); var request = new RestRequest("/files/upload", Method.POST); request.AddFile("file", "C:\\Users\\User\\Documents\\example.pdf"); IRestResponse response = client.Execute(request);
var client = new RestClient("https://api.example.com"); var request = new RestRequest("/files/upload", Method.POST); byte[] fileBytes = File.ReadAllBytes("C:\\Users\\User\\Documents\\example.pdf"); request.AddFile("file", fileBytes, "example.pdf", "application/pdf"); IRestResponse response = client.Execute(request);In this example, a file named "example.pdf" located at "C:\Users\User\Documents\" is read into a byte array which is then uploaded to the RESTful web service at the endpoint "/files/upload". The file is added to the request payload with a key value of "file". The name of the file being uploaded as well as its content type are also specified. The RestSharp library is the package library used in these examples.