Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

Commented Issue: [Regression]Multipart parser not setting content length header on inner contents [1064]

$
0
0
Attached a repro.

__Issue__:
The below action is returning null when actually there is valid data in the content. The issue here is that the content header ‘Content-Length’ value is 0 even though the underlying stream length is actually greater than 0…since the content-length is 0, the deserialization thinks that there is no content to be deserialized and hence returns default value for the C# type(DataPack here) which is null.
```
[HttpPost("MultipartPost")]
public async Task<DataPack> MultipartPost()
{
MultipartMemoryStreamProvider provider = await Request.Content.ReadAsMultipartAsync();

HttpContent content = provider.Contents[0];

return await content.ReadAsAsync<DataPack>();
}
```

__Workaround__:
```
[HttpPost("MultipartPost")]
public async Task<DataPack> MultipartPost()
{
MultipartMemoryStreamProvider provider = await Request.Content.ReadAsMultipartAsync();

HttpContent content = provider.Contents[0];

// workaround
Stream stream = await content.ReadAsStreamAsync();
content.Headers.ContentLength = stream.Length;

return await content.ReadAsAsync<DataPack>();
}
```
Comments: fixed in https://aspnetwebstack.codeplex.com/SourceControl/changeset/ad2acc85d23003aecf133c5a65d45fc7a4c0e646

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>