public static async Task UploadFile(string apiURL, string accessToken, string filePath) { String result = String.Empty; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); using (var content = new MultipartFormDataContent()) { HttpContent stringContent = new StringContent(Path.GetFileNameWithoutExtension(filePath)); content.Add(stringContent, "filename", Path.GetFileNameWithoutExtension(filePath)); var fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filePath)); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "file", FileName = Path.GetFileName(filePath) }; content.Add(fileContent); try { HttpResponseMessage response = await client.PostAsync(apiURL, content); response.EnsureSuccessStatusCode(); // equivalent of pressing the submit button on the form if (response.IsSuccessStatusCode) result = response.Content.ReadAsStringAsync().Result; } catch (Exception ex) { throw ex; } } } return result; }