private static async Task <MultipartPayloadReader> CreateStubReaderThatReturns(string expectedContent, Stream actualStream) { using (Stream contentStream = expectedContent.AsStream()) { var multipartContent = new MultipartFormDataContent { { new StreamContent(contentStream), "name", "filename" } }; await multipartContent.CopyToAsync(actualStream); actualStream.Position = 0; return(MultipartPayloadReader.TryCreate( actualStream, multipartContent.Headers.ContentType.ToString()).Item2); } }
public async Task <IActionResult> Upload() { (bool success, MultipartPayloadReader reader)result = MultipartPayloadReader.TryCreate(Request.Body, Request.ContentType); if (!result.success) { return(BadRequest($"Expected a multipart request, but got {Request.ContentType}")); } string payloadId = await UploadPayloadsWith(result.reader); string downloadUrl = FormatWithDownloadUrl(payloadId); return(new OkObjectResult(new UploadResult(payloadId, downloadUrl))); }
public void CannotCreateReader_IfContentTypeIsntMultiPart() { Assert.False(MultipartPayloadReader.TryCreate(Stream.Null, "application/json").Item1); }