Here is the code that I use to send form information and csv file
using (var httpClient = new HttpClient()) { var surveyBytes = ConvertToByteArray(surveyResponse); httpClient.DefaultRequestHeaders.Add("X-API-TOKEN", _apiToken); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var byteArrayContent = new ByteArrayContent(surveyBytes); byteArrayContent.Headers.ContentType = MediaTypeHeaderValue.Parse("text/csv"); var response = await httpClient.PostAsync(_importUrl, new MultipartFormDataContent { {new StringContent(surveyId), "\"surveyId\""}, {byteArrayContent, "\"file\"", "\"feedback.csv\""} }); return response; }
This is for .net 4.5.
Note the \ "in the MultipartFormDataContent file. There is an error in the MultipartFormDataContent file .
In 4.5.1, MultipartFormDataContent wraps data with valid quotation marks.
source share