I am developing an MVC ApiController
that manages the serialization of uploaded files.
I access the content of the uploaded file with this method:
public class UploadController : ApiController
{
[System.Web.Http.HttpPost]
public UploadOutcome UploadFile()
{
HttpContent selectFile = Request.Content;
UploadOutcome res = null;
//implements the serialization logic
SerializerManager serializer = new SerializerManager();
try
{
string content = selectFile.ReadAsStringAsync().Result;
res = serializer.Serialize(content);
}
catch(Exception ex)
{
throw ex;
}
return res;
}
}
The Request.Content.ReadAsStringAsync().Result
is a widely used solution. See here and here.
Unfortunately the obtained content
string contains both the content and the headers of the HttpRequestMessage
:
File content
920-006099 ;84;65;07/03/2014 00:00;13/03/2014 23:59;10;BZ;1
RL60GQERS1/XEF;1499;1024;07/03/2014 00:00;13/03/2014 23:59;5;KV;1
Content string
-----------------------------11414419513108
Content-Disposition: form-data; name="selectFile"; filename="feed.csv"
Content-Type: text/csv
920-006099 ;84;65;07/03/2014 00:00;13/03/2014 23:59;10;BZ;1
RL60GQERS1/XEF;1499;1024;07/03/2014 00:00;13/03/2014 23:59;5;KV;1
-----------------------------11414419513108--
QUESTION
Is there a way to get rid of the headers? In other words, I want to get the content without the headers.