IFormFile没有被dropzone uploadMultiple请求填充 [英] IFormFile not being populated by dropzone uploadMultiple request

查看:246
本文介绍了IFormFile没有被dropzone uploadMultiple请求填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是IFormFile列表没有填充给定的文件,但是当我调用HttpContext.Request.Form.Files时;然后我可以访问这些文件。我更喜欢使用IFormFile,因为它似乎是新的Dotnet core 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.

我有以下请求有效载荷:

I have the following request payload:

使用以下请求标头:

With the following request headers:

和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请求填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆