Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Unassigned: [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>();
}
```

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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