Microsoft.AspNetCore.WebUtilities: FileMultipartSection.FileStream.Length is missing value initially #58555
Labels
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Is there an existing issue for this?
Describe the bug
Hi, I work with AWS SDK for .NET team. Customer reported an issue in our GitHub repository where exception
System.Net.Http.HttpRequestException: Unable to write content to request stream; content would exceed Content-Length.
when using our package.In our AWS SDK for .NET package, we inspect
Stream.Length
property to determine, if for large files we should use multi-part upload (which is basically equivalent to uploading stream/file in chunks).In customer's scenario, they are using MultipartSection class from Microsoft.AspNetCore.WebUtilities namespace, which is used to process the uploaded form file via HTTP POST (customer is using VS Code
Thunder Client
extension to invoke the Web API in the code sample attached in aws/aws-sdk-net#3201 (comment)).During our investigation, we found that in
Microsoft.AspNetCore.WebUtilities
package targeting .NET 7.0 and .NET 8.0,FileMultipartSection.FileStream.Length
could be missing value initially (in .NET 6.0,fileSection.FileStream.Length
always has the value). Kindly refer aws/aws-sdk-net#3201 (comment) for more details.Please advise if this could be fixed in
Microsoft.AspNetCore.WebUtilities
package.Expected Behavior
FileMultipartSection.FileStream.Length
should always have a value when usingMicrosoft.AspNetCore.WebUtilities
package targeting .NET 7.0 and .NET 8.0 (similar to .NET 6.0 target).Steps To Reproduce
Below is the simple reproduction (extracted from sample project attached in aws/aws-sdk-net#3201 (comment)).
.NET 8.0
..csproj
POST
request with file upload using any tool like Postman.RESULT:
fileSection?.FileStream?.Length
would be0
.Executing
fileSection.FileStream.CopyTo(new MemoryStream())
in Immediate Window populates theLength
property.Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: