使用plupload与MVC3 [英] Using plupload with MVC3

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

问题描述

所以,我实现了plupload在MVC3使用Flash运行时。

So, I've implemented plupload using flash runtime in MVC3.

它完美,因为它使用上传纠正行动并运行它所有的感觉。但是,我真的很想能够控制的响应,并在plupload处理它,但我似乎无法打通任何回应。

It works perfectly, in the sense that it uploads using the correction Action and runs it all. However, I'd really like to be able to control the response, and handle it in plupload, but I can't seem to get any response through.

我试过重写fileUploaded,但我似乎无法得到任何东西出来的论点。我试图返回简单的字符串,JSON和你有什么。我似乎无法得到任何东西了在客户端。当然正通过发送闪,我甚至不能与调试萤火虫的要求:/

I've tried overriding fileUploaded, but I can't seem to get anything out of the arguments. I've tried return simple strings, json and what have you. I can't seem to get anything out on the client side. And of course being sent through flash, I can't even debug the requests with firebug :/

与错误事件,并抛出异常一样。它正确地跨$ P $点的异常作为一个错误,但它始终是#IO ERROR一些code像2038或东西出来的另一端。我根本无法显示我的异常字符串或任何东西。谁能帮助?

The same with the Error event, and throwing exceptions. It correctly interprets the exception as an error, but it's always that #IO ERROR with some code like 2038 or something coming out the other end. I can't show my exception string or anything at all. Can anyone help?

奖金的问题:我将如何发送会话/ Cookie数据与plupload一起,所以我可以在我的行动访问会话

Bonus question: How would I send session/cookie data along with the plupload, so I can access the session in my action?

推荐答案

以下为我工作:

[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 Json(new { message = "chunk uploaded", name = name });
}

和客户端上的:

$('#uploader').pluploadQueue({
    runtimes: 'html5,flash',
    url: '@Url.Action("Upload")',
    max_file_size: '5mb',
    chunk_size: '1mb',
    unique_names: true,
    multiple_queues: false,
    preinit: function (uploader) {
        uploader.bind('FileUploaded', function (up, file, data) {
            // here file will contain interesting properties like 
            // id, loaded, name, percent, size, status, target_name, ...
            // data.response will contain the server response
        });
    }
});

至于奖金问题而言,我愿意回答这个问题由不使用会话,因为他们没有很好地扩展,而是因为我知道,你可能会不喜欢这个答案你有可能性通过使用一个会话ID在请求中的 multipart_params

multipart_params: {
    ASPSESSID: '@Session.SessionID'
},

和然后在服务器上<一href=\"http://$c$c.google.com/p/swfupload/source/browse/swfupload/trunk/samples/asp.net/Global.asax?r=705\">perform一些黑客,以创建正确的会话。

and then on the server perform some hacks to create the proper session.

这篇关于使用plupload与MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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