public async Task <ActionResult> UploadFile() { var boundary = UploadHelper.GetBoundary(Request.ContentType); var reader = new MultipartReader(boundary, Request.Body, UploadHelper.MultipartReaderBufferSize); var valuesByKey = new Dictionary <string, string>(); MultipartSection section; while ((section = await reader.ReadNextSectionAsync()) != null) { var contentDispo = section.GetContentDispositionHeader(); if (contentDispo.IsFileDisposition()) { if (!valuesByKey.TryGetValue("sessionId", out var sessionId)) { return(BadRequest()); } var fileSection = section.AsFileSection(); var client = GetSessionClient(); client.UploadResource(sessionId, fileSection.FileStream, fileSection.FileName); } else if (contentDispo.IsFormDisposition()) { var formSection = section.AsFormDataSection(); var value = await formSection.GetValueAsync(); valuesByKey.Add(formSection.Name, value); } } return(Json(new { })); }