asp.net-mvc – 如何使用ASP.NET MVC的plupload包?

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 如何使用ASP.NET MVC的plupload包?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用 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>

文件准备好了

$("#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
});

解决方法

干得好:
[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,buffer.Length);
        fs.Write(buffer,buffer.Length);
    }
    return Content("chunk uploaded","text/plain");
}

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

原文链接:https://www.f2er.com/aspnet/253545.html

猜你在找的asp.Net相关文章