大米1982 2015-07-13 08:51 采纳率: 25%
浏览 4031

mvc中使用uploadify 无法上传大文件 提示超过长度

我使用uploadify上传 修改的配置文件可是还是无法上传超过4M的文件
view代码

  <link href="~/Scripts/jquery.uploadify-v2.1.0/default.css"  rel="stylesheet" type="text/css" />
    <link href="~/Scripts/jquery.uploadify-v2.1.0/uploadify.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="~/Scripts/JQuery/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="~/Scripts/jquery.uploadify-v2.1.0/swfobject.js"></script>

    <script type="text/javascript" src="~/Scripts/jquery.uploadify-v2.1.0/jquery.uploadify.min.js"></script>

    <script type="text/javascript">
        function flashChecker() {
            var hasFlash = 0;    //是否安装了flash
            var flashVersion = 0;  //flash版本

            if (document.all) {
                var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
                if (swf) {
                    hasFlash = 1;
                    VSwf = swf.GetVariable("$version");
                    flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
                }
            } else {
                if (navigator.plugins && navigator.plugins.length > 0) {
                    var swf = navigator.plugins["Shockwave Flash"];
                    if (swf) {
                        hasFlash = 1;
                        var words = swf.description.split(" ");
                        for (var i = 0; i < words.length; ++i) {
                            if (isNaN(parseInt(words[i]))) continue;
                            flashVersion = parseInt(words[i]);
                        }
                    }
                }
            }
            return { f: hasFlash, v: flashVersion };
        }

        var fls = flashChecker();
        var s = "";
        //if (fls.f) document.write("您安装了flash,当前flash版本为: " + fls.v + ".x");
        //else document.write("您没有安装flash");
        $(document).ready(function () {
            $("#uploadFile").uploadify({
                /*注意前面需要书写path的代码*/
                'swf': '../../Scripts/jquery.uploadify-v2.1.0/uploadify.swf',
                'uploader': '/Base/uploadhandler', //请求的Action  
                'cancelImg': '../../Scripts/Scripts/jquery.uploadify-v2.1.0/cancel.png',
                'method': 'get',
                'queueID': 'fileQueue', //和存放队列的DIV的id一致   
                'fileObjName': 'uploadFile',//和input的name属性值保持一致就好,Struts2就能处理了    
                'auto': true, //是否自动开始   
                'multi': true, //是否支持多文件上传   
                'buttonText': '上传', //按钮上的文字  
                'simUploadLimit': 1, //一次同步上传的文件数目   
                'sizeLimit': 100 * 1024 * 1024, //设置单个文件大小限制                  
                //          'fileDesc'     : '支持格式:jpg/gif/jpeg/png/bmp.', //如果配置了以下的'fileExt'属性,那么这个属性是必须的   
                //          'fileExt'       : '*.jpg;*.gif;*.jpeg;*.png;*.bmp',//允许的格式     
                'queueSizeLimit': 5, //限制在一次队列中的次数(可选定几个文件)。默认值= 999,而一次可传几个文件有 simUploadLimit属性决定。  
                'fileSizeLimit': 100 * 1024 * 1024, //设置单个文件大小限制,单位为byte ,100M  
                'removeCompleted': true,
                'removeTimeout': 0.5,
                'requeueErrors': true,

                'onUploadComplete': function (file) {
                    //  $("#result").append("<div>文件"+file.name+"上传成功!</div><br/>");  
                },
                'onUploadSuccess': function (file, data, response) {
                    if ($("#hidFile").val() == "") {
                        $("#hidFile").val(data);
                        $("#showFile").text(data);
                    } else {
                        $("#hidFile").val($("#hidFile").val() + "|" + data + "");
                        $("#showFile").text($("#showFile").text() + ";" + data + "");
                    }
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString, swfuploadifyQueue) {
                    $("#result").html(errorString);  
                },
            });

        });
    </script>
</head>
<body class="easyui-layout">

    <div class="item2 mt15">
        <span class="reg-tit3">上传附件:</span>
        <div class="reg-inf">
            <input type="file" name="uploadFile" id="uploadFile" class="pub-btn" />
            <div id="fileQueue"></div>
            @*<a href="javascript:$('#uploadFile').uploadify('upload','*')">上传文件</a>
                <a href="javascript:$('#uploadFile').uploadify('cancel', '*')">取消所有上传</a>*@
        </div>
        <label id="showFile" name="showFile"></label>
    </div>
    <div class="fl ml158 mt5 f12 gray0">最多可添加5个附件,单个文件大小不得超出10M,<br>可上传文件格式:pdf、doc、docx、xls、ppt、wps、zip、rar、txt、jpg、jpeg、gif、bmp、swf、png、lsp;</div>
</body>

controller 代码


        public string UploadHandler()
        {
            HttpPostedFileBase file = Request.Files["uploadFile"];
            if (file != null)
            {
                string path = Server.MapPath("~/UploadFile");
                string pathWjj = System.DateTime.Now.ToString("yyyyMMdd");
                string root = path + "/" + pathWjj;
                if (!Directory.Exists(root))
                {
                    Directory.CreateDirectory(root);
                }
                file.SaveAs(root + "/" + file.FileName);
                return pathWjj + "/" + file.FileName;
            }
            else
            {
                return "0";
            }
        }

配置文件

 <system.web>
    <httpRuntime maxRequestLength="40960"   
    executionTimeout="6000"
    />
  </system.web>
     <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
    <security >
      <requestFiltering>
        <requestLimits maxAllowedContentLength="40960"></requestLimits>

      </requestFiltering>
    </security>

  </system.webServer>
  • 写回答

4条回答 默认 最新

  • JAVA-SON 2015-07-13 09:19
    关注

    配置里最大允许长度可以商榷。

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题