问题描述
我遇到的问题是 IFormFile 的列表没有填充给定的文件,但是当我调用 HttpContext.Request.Form.Files 时;然后我可以访问这些文件.我更喜欢使用 IFormFile,因为它似乎是新的 Dotnet 核心 2.0 做事方式.
The problem I am having is that the List of IFormFile is not being populated with the given files but when i call HttpContext.Request.Form.Files; then I have access to the files. I would prefer to use IFormFile as it seems to be new Dotnet core 2.0 way of doing things.
我有以下请求负载:
具有以下请求标头:
和 Razor 页面处理程序:
And Razor pages handler:
public async Task<ActionResult> OnPostSend(ConditionResponse conditionResponse)
{
var files = HttpContext.Request.Form.Files;
}
条件响应模型:
public class ConditionResponse
{
public List<string> Plots { get; set; }
public string Comments { get; set; }
public List<IFormFile> Files { get; set; }
}
推荐答案
在查看来自 html5 多文件上传的请求后,我注意到该请求没有将索引添加到文件名 (files[n]).Dropzone.js 这样做,所以有一个变通办法.如果您将 paramName 选项添加到 Dropzone JS 配置并让它调用返回文件的方法,您将获得与 html5 多文件上传相同的行为.
After looking at the request from a html5 multiple file upload I noticed the request does not add the indexes to the filename (files[n]). Dropzone.js does this so there is a work around. If you add the paramName option to Dropzone JS config and have it call a method which returns files you will get the same behaviour as the html5 multiple file upload.
function myParamName() {
return "files";
}
Dropzone.options.myDropzone = {
uploadMultiple: true,
paramName: myParamName,
}
这篇关于IFormFile 未被 dropzone uploadMultiple 请求填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!