.NET 10, ReadNextSectionAsync has bug,when postman submit single file throw System.IO.InvalidDataException:“The stream exceeded the data limit 16384.”, when postman submit 1+ files, ReadNextSectionAsync never return null。
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
.NET 10, ReadNextSectionAsync has bug,when postman submit single file throw System.IO.InvalidDataException:“The stream exceeded the data limit 16384.”, when postman submit 1+ files, ReadNextSectionAsync never return null。
```
protected override async Task?> HandleAsync(
HttpRequest request,
CancellationToken token = default)
{
if (!MediaTypeHeaderValue.TryParse(request.ContentType, out var mediaTypeHeader) ||
string.IsNullOrWhiteSpace(mediaTypeHeader.Boundary.Value))
throw HttpApiExceptions.BadRequest($"`Content-Type` is form-data, but `boundary` not found");
var boundary = HeaderUtilities.RemoveQuotes(mediaTypeHeader.Boundary).Value ?? throw HttpApiExceptions.BadRequest($"`Content-Type` is form-data, but `boundary` not found");
var reader = new MultipartReader(boundary, request.Body);
var section = await reader.ReadNextSectionAsync(token);
var hasWebBlob = false;
var storageOptions = BlobStorageService.Options;
var webBlobs = new Lazy>(() => new List(storageOptions.MaxFilesPerTime));
while (section != null)
{
var disposition = section.GetContentDispositionHeader();
if (disposition != null &&
disposition.IsFileDisposition() &&
!string.IsNullOrWhiteSpace(disposition.FileName.Value))
{
var fileSection = section.AsFileSection();
if (fileSection?.FileStream is null) continue;
var fileType = Path.GetExtension(disposition.FileName).ToString();
if (!storageOptions.IsFileTypePermitted(fileType))
throw HttpApiExceptions.BadRequest($"Illegal file type:{fileType}");
// handle file upload
}
// .NET 10, ReadNextSectionAsync has bug,when postman submit single file throw System.IO.InvalidDataException:“The stream exceeded the data limit 16384.”, when postman submit 1+ files, ReadNextSectionAsync never return null。
section = await reader.ReadNextSectionAsync(token);
}
return hasWebBlob ? webBlobs.Value : null;
}
```
### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.