输入类型=文件默认大小限制3Mb

时间:2017-01-05 08:12:37

标签: javascript c# html asp.net-mvc

我正在使用MVC 5和visual studio 2015。

我已成功实施文件上传。 客户端代码:

<label for="file-upload" class="btn btn-primary">Save attachment</label>
<input id="file-upload" type="file" multiple style="display:none;" />

客户端脚本:

 $(function () {

    $("#file-upload").click(function (event) {
      $("#file-upload").val("");
    });


    $("#file-upload").on('change', function (event) {
      debugger;
      var iNEWS_KEY = $('input[name = "iNEWS_KEY"]').val();
      var formData = new FormData();
      var totalFiles = document.getElementById("file-upload").files.length;
      for (var i = 0; i < totalFiles; i++) {
        var file = document.getElementById("file-upload").files[i];

        formData.append("file-upload", file);
      }
      $.ajax({
        type: "POST",
        url: '/NewsInternal/Upload',
        data: formData,
        dataType: 'json',
        contentType: false,
        processData: false,
        success: function (response) {

          var count = response.listAttachments.length;
          $("#tableNewsInternal > tbody > tr[id='" + iNEWS_KEY + "'] > td[id='tdAttachment']").html(count);
          $("#tblNewsAttachments > tbody > tr").remove();

          for (i = 0; i < count; i++) {
            var z = i + 1;
            var iNEFI_KEY = response.listAttachments[i].iNEFI_KEY;
            var cNEFI_LINK = response.listAttachments[i].cNEFI_LINK;

            var btnDelete = '<button type="button" class="btn btn-danger" onclick="DeleteAttachment(' + iNEFI_KEY + ');" style="width:100px;">Izbriši</button>';

            $("#tblNewsAttachments > tbody").append("<tr id='" + iNEFI_KEY + "'><td style='padding-right:15px;'>" + z + "."
              + "</td><td style='padding-right:15px;'>" + response.listAttachments[i].cNEFI_ORI
              + "</td><td>" + btnDelete + "</td><td>" + cNEFI_LINK + "</td></tr>");
          }
        },
        error: function (error) {
          alert("Napaka pri dodajanju priponke!");
        }
      });
    });

});

在服务器端:

[HttpPost]
public JsonResult Upload()

一切都运作良好。我的问题是,无法上传大于3MB的文件。如果我试试,f.e。上传文件4MB大,没有触发服务器操作(我在服务器上的操作上设置了断点。永远不会达到断点)并且响应是:

[HttpException]: Maximum request length exceeded.

我的代码出了什么问题?限制3MB来自哪里?

0 个答案:

没有答案