private async Task LoadMultiPart(WebROCollection form) { string boundary = GetParameter(ContentType.AsSpan(), "; boundary="); if (boundary == null) { return; } using (var requestStream = InputStream) { // DB: 30/01/11 - Hack to get around non-seekable stream and received HTTP request // Not ending with \r\n? var ms = new MemoryStream(32 * 1024); await requestStream.CopyToAsync(ms).ConfigureAwait(false); var input = ms; ms.WriteByte((byte)'\r'); ms.WriteByte((byte)'\n'); input.Position = 0; // Uncomment to debug // var content = new StreamReader(ms).ReadToEnd(); // Console.WriteLine(boundary + "::" + content); // input.Position = 0; var multi_part = new HttpMultipart(input, boundary, ContentEncoding); HttpMultipart.Element e; while ((e = multi_part.ReadNextElement()) != null) { if (e.Filename == null) { byte[] copy = new byte[e.Length]; input.Position = e.Start; await input.ReadAsync(copy, 0, (int)e.Length).ConfigureAwait(false); form.Add(e.Name, (e.Encoding ?? ContentEncoding).GetString(copy, 0, copy.Length)); } else { // We use a substream, as in 2.x we will support large uploads streamed to disk, var sub = new HttpPostedFile(e.Filename, e.ContentType, input, e.Start, e.Length); files[e.Name] = sub; } } } }