IFormFile not being populated by dropzone uploadMu

2019-03-28 08:29发布

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.

I have the following request payload: request payload

With the following request headers: request headers

And Razor pages handler:

public async Task<ActionResult> OnPostSend(ConditionResponse conditionResponse)
    {
        var files = HttpContext.Request.Form.Files;
    }

Condition response model:

public class ConditionResponse
{
    public List<string> Plots { get; set; }

    public string Comments { get; set; }

    public List<IFormFile> Files { get; set; }
}

2条回答
够拽才男人
2楼-- · 2019-03-28 08:44

The accepted answer worked perfectly, I am not sure why and how, but it works. I just wanted to get rid of that additional function, i.e., we can use it like this:

 Dropzone.options.myDropzone = {
                uploadMultiple: true,
                paramName: () => "files",
}

Or if old browsers are also targeted:

 Dropzone.options.myDropzone = {
                uploadMultiple: true,
                paramName: function () { "files" },
}
查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-28 08:58

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,
}
查看更多
登录 后发表回答