![StreamContent StreamContent]()
This answer explains how to change this limit using a custom Web.config (included below for completeness):<?xml version="1.0" encoding="utf-8"?><configuration> <system.webServer> <security> <requestFiltering> <!-- 1 GB --> <requestLimits maxAllowedContentLength="1073741824" /> </requestFiltering> </security> </system.webServer></configuration>作为旁注:As somewhat of a side note:除非有特殊原因,否则可以避免在代码中使用MemoryStream,而直接将fs传递到new StreamContent(...)中.您可以对Request.Body流执行类似的操作,并将其直接复制到输出FileStream中.最终结果是:Unless you have a specific reason to do so, you can avoid the use of MemoryStream in your code and just pass fs directly into new StreamContent(...). You can do something similar with the Request.Body stream and copy that directly into the output FileStream. This would end up with:public async Task PostDirAsync(string localDirPath, string serverDir){ var sourcePath = Path.Combine("Temp", Guid.NewGuid() + ".zip"); ZipFile.CreateFromDirectory(localDirPath, sourcePath, CompressionLevel.Fastest, true); var streamContent = new StreamContent(File.Open(sourcePath, FileMode.Open)); streamContent.Headers.Add("Content-Type", "application/octet-stream"); var resp = await _client.PostAsync("api/File/PostDir?serverPath={WebUtility.UrlEncode(serverDir)}", streamContent);}并且:[HttpPost("PostDir")][DisableRequestSizeLimit]public async Task<IActionResult> PostDir(string serverPath){ var zipName = Path.Combine(_config["QuickDrive:TempDir"], Guid.NewGuid() + ".zip"); using (var fileStream = System.IO.File.Create(zipName)) await Request.Body.CopyToAsync(fileStream ); return Ok();} 这篇关于为什么我会收到404尝试将大文件发布到Core Web API的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 15:29