本文介绍了Microsoft.AspNetCore.WebUtilities超出行长度限制100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试进行自动化测试,以将文本文件上传到使用flowjshandler的Web api,这些文件均在c#.net core和linux docker容器中运行.从Visual Studio运行时,测试程序会无例外地上传文件.但是,如果我在容器中运行测试程序和Web api,则会在asp .net核心Web api框架中得到此异常:

I've have been trying to automate a test in to upload a text file to a web api which uses flowjshandler, all running in c# .net core and linux docker containers. The test program uploads the file without exceptions when run from visual studio. However if I run the test program and web api inside a container I get this exception in the asp .net core web api framework:

我查看了 Microsoft.AspNetCore.WebUtilities ,发现了错误的出处,但不确定如何避免100个字符的限制.我试图更改上传文件.

I've look at Microsoft.AspNetCore.WebUtilities and found where the error is coming from but not sure how to avoid 100 character limit. I have tried to vary the upload files.

这是包含内容的多部分消息

It is a multi part message with content

Content-Type: multipart/form-data; boundary=----WebKitFormBoundarym45GFZc25WVhjtVB
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowChunkNumber"

1
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowChunkSize"

1048576
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowCurrentChunkSize"

440
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowTotalSize"

440
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowIdentifier"

440-Boundarystxt
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowFilename"

Boundarys.txt
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowRelativePath"

Boundarys.txt
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="flowTotalChunks"

1
------WebKitFormBoundarym45GFZc25WVhjtVB
Content-Disposition: form-data; name="file"; filename="Boundarys.txt"

推荐答案

在Linux容器上运行时,我正在使用 Environment.Newline 不能识别行尾.在内容处置:表单数据中将换行符更改为 \ r \ n .

I was using Environment.Newline when running on linux containers does not recognize the end of line. Changed Newline to be \r\n in the Content-Disposition: form-data.

var nl = "\r\n";
sb.AppendFormat($"{nl}{BOUNDARY}{nl}Content-Disposition: form-data; name=\"flowChunkNumber\"{nl}{nl}{flowFileUpload.flowChunkNumber}{nl}{BOUNDARY}{nl}Content-Disposition: form-data; 

这篇关于Microsoft.AspNetCore.WebUtilities超出行长度限制100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 05:14