asp.net – 超过IIS 7.5和.NET中的2GB文件上载限制

我有一个内部网应用程序,需要上传(.iso)超过2GB的文件.看来2GB文件大小有很多限制因素.

> IE中存在浏览器限制,只有IE 9/10可以超过2GB According to Eric Law
> httpRuntime的maxRequestLength元素的类型为Int32,其最大值为2097151,大约为2GB.

看来你可以设置另一个文件大小限制,其中maxAllowedContentLength大约为4GB,因为它是uint类型,但是当我们仍然受到maxRequestLength的2GB限制时有什么好处呢?

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="4294967295" />
    </requestFiltering>
  </security>
<system.webServer>

有没有人有任何上传文件超过2GB限制的解决方案?

最佳答案
您是否对JavaScript解决方案开放?如果是这种情况尝试this jQuery插件,它允许您上传海量数据(很多GB).
如果浏览器不支持提供受TCP / IP发送和接收包相应ACK的机制,则使用HTML5 FileReader API功能和Silverlight回退上传文件.文件按配置大小上传(默认为4 MB).

另外:它还带有文件队列模式.

以下是如何在Razor视图中使用它的示例:

$(function () {

    var file = $("#file").createUploaderHtml5({
        postDataUrl: "@Url.Action("Upload", "Home")",
        packetSize: 4 * 1024 * 1024,
        onPreparingUpload: function (plugin, ufname, umime, usize) {
            plugin.settings.logger("ufname = [" + ufname + "] umime = [" + umime + "] usize = [" + usize + "]");
            return true;
        },
        onInitPacketArrived: function (plugin, guid) {
            plugin.settings.logger("guid = [" + guid + "]");
        },
        onDataPacketArrived: function (plugin, ack, total) {
            //plugin.settings.logger("ACK [" + ack.Guid + "] packet = [" + ack.Packet + "] total = [" + total + "]");
            var percent = Math.round(ack.Packet / total * 100);
            $("#progressbar").attr("value", percent);
            $("#percent").html(percent + " %");
        },
        onFileUploaded: function (pl) {
            pl.settings.logger("File finished!!!");
        },
        logger: function(msg) {
            var lg = $("#logger");
            lg.html(lg.html() + msg + "<br />");
        }
    });

    $("#start").click(function () {
        file.startUpload();
    });

    $("#stop").click(function () {
        file.cancelUpload();
    });

});

这是上传操作的代码:

[HttpPost]
public ActionResult Upload(FormCollection collection)
{
    var packetSize = 4 * 1024 * 1024; // default to 4 MB
    var filePath = Server.MapPath("~/_temp_upload/");

    var result = UploadHelper.ProcessRequest(Request, filePath, packetSize);

        if (result != null)
        {
            var metadata = UploadHelper.GetMetadataInfo(filePath, result.Guid);
            // do anything with the metadata
        }

        if (result != null)
            return Json(result);
        return Content("");
    }

转载注明原文:asp.net – 超过IIS 7.5和.NET中的2GB文件上载限制 - 代码日志