コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
 public void CannotCreateReader_IfContentTypeIsntMultiPart()
 {
     Assert.False(MultipartPayloadReader.TryCreate(Stream.Null, "application/json").Item1);
 }