使用RestSharp将数据文件上传到.Net Core 2.1 REST界面时,在某些文件上出现此错误:
System.IO.InvalidDataException: Line length limit 100 exceeded.
at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.ReadLineAsync(Int32 lengthLimit, CancellationToken cancellationToken)
at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)
at Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken cancellationToken)
当我对Insomnia进行相同的操作时,仅使用RestSharp我不会得到任何错误。
我在这里Microsoft.AspNetCore.WebUtilities Line length limit 100 exceeded已经读到行尾格式有问题,但这是有关它的唯一文章,它没有提供任何实际的解决方案。
控制器签名非常简单:
[HttpPost, DisableRequestSizeLimit]
public async Task<IActionResult> AddPictureAsync(
IFormFile Picture,
IFormFile Thumbnail,
string Title)
{
,要发送的代码是:
var Request = new RestRequest("picture", Method.POST) { AlwaysMultipartFormData = true };
Request.AddHeader("SessionId", SessionId);
Request.AddFile("Picture", PhotoData.ToArray(), Photo.PhotoUrl);
Request.AddFile("Thumbnail", ThumbnailData, Photo.PhotoUrl.Replace(".jpg", "-t.jpg"));
Request.AddParameter("Title", Photo.Title ?? string.Empty, ParameterType.GetOrPost);
我应该在哪里看?