如何在ASP.NET MVC中使用plupload包?

Lor*_*nzo 22 asp.net-mvc plupload asp.net-mvc-2

我使用的是plupload 1.3.0版

更具体地说,我如何定义控制器动作来支持分块?我可以HttpPosteFileBase用作参数吗?

目前我正在使用以下代码初始化插件

在HEAD标签中

<link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/jquery.ui.plupload.css" )%>" />
<link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/gsl.plupload.css" )%>" />
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/gears_init.js" )%>"></script>
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/plupload.full.min.js" )%>"></script>
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/jquery.ui.plupload.min.js" )%>"></script>
Run Code Online (Sandbox Code Playgroud)

准备好文件

$("#uploader").pluploadQueue({
    runtimes: 'html5,html4,gears,flash,silverlight',
    url: '<%: Url.Content( "~/Document/Upload" ) %>',
    max_file_size: '5mb',
    chunk_size: '1mb',
    unique_names: true,
    filters: [
        { title: "Documenti e Immagini", extensions: "doc,docx,xls,xlsx,pdf,jpg,png" }
    ],
    multiple_queues: false
});
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 43

干得好:

[HttpPost]
public ActionResult Upload(int? chunk, string name)
{
    var fileUpload = Request.Files[0];
    var uploadPath = Server.MapPath("~/App_Data");
    chunk = chunk ?? 0;
    using (var fs = new FileStream(Path.Combine(uploadPath, name), chunk == 0 ? FileMode.Create : FileMode.Append))
    {
        var buffer = new byte[fileUpload.InputStream.Length];
        fileUpload.InputStream.Read(buffer, 0, buffer.Length);
        fs.Write(buffer, 0, buffer.Length);
    }
    return Content("chunk uploaded", "text/plain");
}
Run Code Online (Sandbox Code Playgroud)

对于每个块以及正在上载的每个文件,将多次调用此方法.它将作为参数传递块大小和文件名.我不确定您是否可以使用HttpPostedFileBaseas action参数,因为该名称不是确定性的.

  • SO发布评论算法:1.尝试几天.感到沮丧.2.发表评论.希望.3.在SO Comment发布后立即搞清楚.墨菲的法律感谢达林 (4认同)
  • 小错误 - 第7行应该是name而不是fileName (2认同)