plupload asp.net处理程序不完整的文件

时间:2012-12-07 09:54:57

标签: jquery asp.net handler ashx plupload

当我将运行时设置为“html4”时,一切都运行良好。所有其他运行时(由于您可以一次选择多个文件而更好)似乎工作得很好,除了文件没有完全上传。在几kb(42/28/50)之后,它表示'100%完成'。文件存储且不完整。有什么想法吗?

$("#uploader").plupload({
// General settings
runtimes : 'gears,flash,silverlight,browserplus,html5',
url : 'upload.ashx',
max_file_size : '10mb',
chunk_size : '1mb',
unique_names : true,

// Resize images on clientside if we can
resize : {width : 320, height : 240, quality : 90},

// Specify what files to browse for
filters : [
    {title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
    ],

    // Flash settings
    flash_swf_url : 'js/plupload.flash.swf',

    // Silverlight settings
    silverlight_xap_url : 'js/plupload.silverlight.xap'
});

// Client side form validation
$('form').submit(function(e) {
    var uploader = $('#uploader').plupload('getUploader');

    // Files in queue upload them first
    if (uploader.files.length > 0) {
        // When all files are uploaded submit form
        uploader.bind('StateChanged', function() {
            if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                $('form')[0].submit();
            }
        });

        uploader.start();
    } else
        alert('You must at least upload one file.');

    return false;
});

upload.ashx:

公共类上传:实现IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim chunk As Integer = If(context.Request("chunk") IsNot Nothing, Integer.Parse(context.Request("chunk")), 0)
    Dim fileName As String = If(context.Request("name") IsNot Nothing, context.Request("name"), String.Empty)

    Dim fileUpload As HttpPostedFile = context.Request.Files(0)

    Dim uploadPath = context.Server.MapPath("uploads")
    Using fs = New FileStream(Path.Combine(uploadPath, fileName), If(chunk = 0, FileMode.Create, FileMode.Append))
        Dim buffer = New Byte(fileUpload.InputStream.Length - 1) {}
        fileUpload.InputStream.Read(buffer, 0, buffer.Length)

        fs.Write(buffer, 0, buffer.Length)
    End Using

    context.Response.ContentType = "text/plain"
    context.Response.Write("Success")
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
        Return False
    End Get
End Property

0 个答案:

没有答案