此方法不能在里面再使用MultipartRequestReader.ReadAsync(Request, path)

会报出异常:“Unexpected end of Stream, the content may have already been read by another component”

MultipartRequestReader.ReadAsync(Request, path)是公司里一个封装的比较垃圾的组件, 正常人都不会要request,容错率太低!

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="request">新增数据</param>
        /// <returns>结果</returns>
        [HttpPost("submit")]
        public bool Submit([FromForm] InvoiceSubmitRequest request, IFormCollection formfile)
        {
            string path = _configuration["AttachmentsPath"];
            // var s = Request.Form.Files.Count;
            var invoiceData = request.InvoiceBase.PackJsonObject<InvoiceBaseDto>();
               // Request.Form.Files[0].OpenReadStream().StreamToByte().ByteToStream();

            var uploadFiles =  MultipartRequestReader.ReadAsync(Request, path);
            
            // var toDBFilePath = _filePathHelper.ToDBFilePath(file.Path, file.Name);
            var data = new InvoiceAddDto();
            data.InvoiceBase = invoiceData;

            // data.InvoiceBase.FileRawName = file.RawName;
            // data.InvoiceBase.InvoiceImg = toDBFilePath;
            service.Submit(data);

            // 将原图压缩
            // if (!file.Name.Contains(".pdf"))
            // {
            //     _ = System.Threading.Tasks.Task.Run(() =>
            //       {
            //           _commonService.GetReducedImage(Path.Combine(file.Path, file.Name), Path.Combine(file.Path, file.Name));
            //       });
            // }
            return true;
        }

误打误撞成功

 /// <summary>
        /// 提交
        /// </summary>
        /// <returns>结果</returns>
        [HttpPost("submit")]
        [RequestSizeLimit(100_000_000)]
        public async Task<bool> Submit()
        {
            string path = _configuration["AttachmentsPath"];
            Request.EnableBuffering();
            Request.Body.Position = 0;

            // var files = Request.Form.Files;
            var invoiceBase = Request.Form["InvoiceBase"].PackString();

            var invoiceData = invoiceBase.PackJsonObject<InvoiceBaseDto>();

            // Request.Form.Files[0].OpenReadStream().StreamToByte().ByteToStream();
            var uploadFiles = await MultipartRequestReader.ReadAsync(Request, path);
            if (uploadFiles.Files.Count < 1)
            {
                throw new StatusNotFoundException("Can't read any files.");
            }

            var file = uploadFiles.Files[0];
            var toDBFilePath = _filePathHelper.ToDBFilePath(file.Path, file.Name);
            var data = new InvoiceAddDto();
            data.InvoiceBase = invoiceData;
            data.InvoiceBase.FileRawName = file.RawName;
            data.InvoiceBase.InvoiceImg = toDBFilePath;
            service.Submit(data);

            // 将原图压缩
             if (!file.Name.Contains(".pdf"))
            {
                _ = System.Threading.Tasks.Task.Run(() =>
                  {
                      _commonService.GetReducedImage(Path.Combine(file.Path, file.Name), Path.Combine(file.Path, file.Name));
                  });
            }
            return true;
        }