如何使用plupload包ASP.NET MVC? [英] How to use the plupload package with ASP.NET MVC?

查看:152
本文介绍了如何使用plupload包ASP.NET MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 plupload 版本1.3.0

更具体地讲我是如何定义我的控制器行动支持分块?我可以使用 HttpPosteFileBase 作为参数?

目前我使用下面的code初始化插件

在HEAD标签

 <链接类型=文/ CSS相对=样式媒体=屏幕上的href =<%:Url.Content(〜/ _assets / CSS / plupload / jquery.ui.plupload.css)%>中/>
<链接类型=文/ CSS相对=样式媒体=屏幕上的href =<%:Url.Content(〜/ _assets / CSS / plupload / gsl.plupload.css)%> />
<脚本类型=文/ JavaScript的SRC =<%:Url.Content(〜/ _assets / JS / plupload / gears_init.js)%>>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =<%:Url.Content(〜/ _assets / JS / plupload / plupload.full.min.js)%>>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =<%:Url.Content(〜/ _assets / JS / plupload / jquery.ui.plupload.min.js)%>>< /脚本>

在文件准备好

  $(#上传)。pluploadQueue({
    运行时间:HTML5,HTML4,齿轮,闪光,Silverlight的',
    网址:'<%:Url.Content(〜/文档/上传)%>,
    MAX_FILE_SIZE:5MB,
    CHUNK_SIZE:'1MB',
    unique_names:真实,
    过滤器:
        {标题:DocumentiêImmagini,扩展名:DOC,DOCX,XLS,XLSX,PDF,JPG,PNG}
    ]
    multiple_queues:假的
});


解决方案

在这里你去:

  [HttpPost]
公众的ActionResult上传(INT?大块,字符串名称)
{
    变种文件上传= Request.Files [0];
    VAR uploadPath =使用Server.Mappath(〜/ App_Data文件);
    大块大块=? 0;
    使用(VAR FS =新的FileStream(Path.Combine(uploadPath,姓名),块== 0 FileMode.Create:FileMode.Append))
    {
        VAR缓冲=新的字节[fileUpload.InputStream.Length]
        fileUpload.InputStream.Read(缓冲液,0,buffer.Length);
        fs.Write(缓冲液,0,buffer.Length);
    }
    返回的内容(块上传,text / plain的);
}

正在上载的每个块和每个文件

这个方法将被调用多次。它会通过为参数的块大小和文件名。我不知道作为,因为该名称是不确定是否可以使用 HttpPostedFileBase 作为行动参数。

I am using plupload version 1.3.0

More specifically how I have to define my controller action to support chunking? Can I use the HttpPosteFileBase as a parameter?

At the moment I am using the following code to initialize the plugin

In the HEAD tag

<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>

On document ready

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

解决方案

Here you go:

[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");
}

This method will be called multiple times for each chunk and for each file being uploaded. It will pass as parameter the chunk size and the filename. I am not sure as to whether you could use a HttpPostedFileBase as action parameter because the name is not deterministic.

这篇关于如何使用plupload包ASP.NET MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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