如何在ASP中启用IFormFeature ?网/红隼?



我想处理多部分文件上传,所以在我的处理程序中,我得到这样的IFormFeature:

var formFeature = ctx.Features.Get<IFormFeature>()

然而,它总是null

我的请求是这样的:

curl -v -X POST -H "Content-Type: multipart/form-data" -F records=@big-file.csv localhost:8080/form

我需要做什么才能在ASP中启用IFormFeature?网/红隼?

我只是偶然遇到了这个问题并解决了它。请原谅我的无礼。

ting:

let formContentType = ctx.Request.HasFormContentType

结果为formFeature:

let formFeature = ctx.Features.Get<IFormFeature>()

不再为空

注释let formContentType = ctx.Request.HasFormContentType导致formFeature再次为空。

所以看起来好像属性的getter触发了一些东西来解析,否则不会。

你不需要直接使用IFormFeature,调用HttpRequest.ReadFormAsync()来解析传入的表单。https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httprequest.readformasyncIFormFeature只是缓存结果,这就是为什么它不存在,直到任何表单api被调用(不只是HasFormContentType)。

最新更新