0

I am trying to receive a post from a data provider using a Web API.

When I save the request from my web api with the function below:

public async Task<HttpResponseMessage> Import(HttpRequestMessage request)

and then save the stream from the code below to a file:

var stream = await request.Content.ReadAsStreamAsync();

I get the following result:

--------------------------2226e2cc2af7d11c

Content-Disposition: form-data; name="xml"; filename="test.xml.gz" Content-Type: application/octet-stream

[GZip data goes here...]

--------------------------2226e2cc2af7d11c

Content-Disposition: form-data; name="myId1"

123

--------------------------2226e2cc2af7d11c

Content-Disposition: form-data; name="myId2"

456 --------------------------2226e2cc2af7d11c--

This is of course not a correct GZip format. I then try to handle the request as a multipart request using the code below:

var streamContent = new StreamContent(stream);
streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
var provider = await streamContent.ReadAsMultipartAsync();

But, then the error below appears:

Invalid 'HttpContent' instance provided. It does not have a content type header starting with 'multipart/'

So, my question is, how do I get the gzip data from the xml parameter in the request? I need to save the gzip data and then later on unzip it and process the data.

Thanks!

Fangming
  • 24,551
  • 6
  • 100
  • 90
Fredrik
  • 290
  • 1
  • 8

1 Answers1

0

The solution was to create a custom MultipartFormDataStreamProvider.

I found a solution in this article: Web API: how to access multipart form values when using MultipartMemoryStreamProvider?

Fredrik
  • 290
  • 1
  • 8