Pluupload在服务器上非常慢,在本地主机中它非常快

时间:2015-10-29 02:50:52

标签: jquery asp.net vb.net httphandler

Pluupload在托管服务器上非常慢,在localhost中非常快 在我的本地主机中,当我尝试上传115MB时,它会在30秒内上传,当我尝试在服务器中托管时,它会像普通的asp.net文件上传控制性能一样上传。

除了以下代码,我还需要执行任何设置吗? 如果有人能提出一些建议,那就太棒了

这是我的代码,

     $(document).ready(function () {
        $("#MainFileUpload").pluploadQueue({
            runtimes: 'html5,gears,flash,silverlight,html4',
            buttons: { browse: true, start: false, stop: false },
            url: 'TIABUploadHandler.ashx',
            max_file_size: '150mb',
            chunk_size: '2mb',
            multiple_queues: true,
            multipart: true,
            max_files: 1,
            flash_swf_url: '/js/plupload/plupload.flash.swf',
            silverlight_xap_url: '/js/plupload/plupload.silverlight.xap',
            filters: [
            { title: "Image files", extensions: "jpg,gif" },
            { title: "Zip files", extensions: "zip" },
            { title: "Document files", extensions: "doc,pdf,txt" }
            ],
            init: {
                FilesAdded: function (up, files) {
                    var maxfiles = 1;
                    if (up.files.length > maxfiles) {
                        up.splice(maxfiles);
                        alert('Only one file is allow to upload');
                    }
                    if (files.length > 0) {
                        $.each(files, function (i, file) {
                            var parts = file.name.split('.')
                            var data = guid() + "." + parts[parts.length - 1];
                            $("#CurrentUploadedFileName").val(file.name);
                            $("#CurrentUploadedServerFileName").val(data);
                            $("#CurrentUploadedFileContentType").val(file.type);

                        });
                    }
                    if (up.files.length === maxfiles) {
                        $('#MainFileUpload_browse').hide("slow"); // provided there is only one #uploader_browse on page
                    }
                },
                FilesRemoved: function (up, file) {
                    if (up.files.length === 0) {
                        $('#MainFileUpload_browse').show("slow");
                    }
                    else {
                        $('#MainFileUpload_browse').hide("slow");
                    }
                },
                BeforeUpload: function (up, file) {
                    uploader.settings.multipart_params = { fileId: $("#CurrentUploadedServerFileName").val() };
                }
            }
        });

        var uploader = $('#MainFileUpload').pluploadQueue();
function guid() {
            function _p8(s) {
                var p = (Math.random().toString(16) + "000000000").substr(2, 8);
                return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
            }
            return _p8() + _p8(true) + _p8(true) + _p8();
        }

这是我的处理程序代码

      Dim chunk As Integer = If(context.Request("chunk") IsNot Nothing, Integer.Parse(context.Request("chunk")), 0)
    Dim chunks As Integer = If(context.Request("chunks") IsNot Nothing, Integer.Parse(context.Request("chunks")) - 1, 0)

    Dim fileName As String = If(context.Request("fileId") IsNot Nothing, context.Request("fileId"), String.Empty)

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

    Dim uploadPath = context.Server.MapPath("~/App_Data/")
    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(fileName)

0 个答案:

没有答案