Kendo UI多文件上传问题

时间:2015-04-28 19:36:29

标签: javascript asp.net-mvc razor kendo-upload

我正在使用Kendo文件上传控件上传多个文件。只有少数文件被上传(特别是第一个和最后一个)或一些随机文件。对此有什么解决方案吗?

Index.cshtml:

<input name="files" id="files" type="file" multiple="multiple" />

JS文件:

$("#files").kendoUpload
    ({
        async: {
            saveUrl: "/Controller/GetUserUploadedFiles",
            removeUrl: "/Controller/Remove",
            autoUpload: false,
            allowmultiple: true
        },
        select: function (e) {
            onSelect(e);
        },
        success: function (e) {
        },
        error: function (e) {
        }
    });

//控制器方法

[HttpPost]
   public void GetUserUploadedFiles(IEnumerable<HttpPostedFileBase> files)
   {   
     //Custom logic here
   }

另外,如果我可以在一个控制器方法调用中将所有文件作为Enumerable而不是多次调用多个文件,那将会很棒。

我有什么遗漏或做错了吗?

谢谢, 作者Srini

2 个答案:

答案 0 :(得分:1)

此代码将上传在Kendo Upload中选择的所有文件,然后在每个文件上运行代码。

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key here" />

您可以使用以下方式获取文件名:

[HttpPost]
public void GetUserUploadedFiles()
{   
    Request.Content.LoadIntoBufferAsync().Wait();
    var result = Task.Factory
                 .StartNew(() => Request.Content.ReadAsMultipartAsync().Result,
                  CancellationToken.None,
                  TaskCreationOptions.LongRunning,
                  TaskScheduler.Default).Result;

    var contents = result.Contents;
    HttpContent httpContent = contents.First();        

    Stream file = httpContent.ReadAsStreamAsync().Result;

    if (file.CanRead)
    {
        // Code that will be executed on each file
    }
}

您可以使用以下方式获取上传的文件媒体类型:

string filename = httpContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);

答案 1 :(得分:0)

IIRC,如果同时选中,则剑道批处理选项仅将文件作为集合上载(浏览,然后选择多个文件)。一旦您选择了其他文件,它们将在另一个请求中发送。在同一请求期间强制文件发布的唯一方法是使用同步模式而不是异步。祝好运。