Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exceeding the 2GB file upload limitation in IIS 7.5 and .NET

I have an intranet application that needs to upload (.iso) files that exceed 2GB. It appears there are many limiting factors to the 2GB file size.

  1. There is a browser limitation within IE and only IE 9/10 can exceed 2GB According to Eric Law
  2. The maxRequestLength element of httpRuntime is of type Int32, which has a maximum value of 2097151, approximately 2GB.

It appears you can set yet another file size limit with with maxAllowedContentLength to approximately 4GB as it is of type uint, but what good does that do when we still are being limited by 2GB from maxRequestLength?

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

Does anyone have any solutions for uploading files past the 2GB limit?

like image 284
m4chine Avatar asked May 24 '13 15:05

m4chine


1 Answers

Are you open for JavaScript Solution??. If that's the case try this jQuery plugin which allows you to upload massive data(a lot GB). It upload files using HTML5 FileReader API features and Silverlight fallback if browser doesn't have support providing a mechanism inspired on TCP/IP send and receive packages with the corresponding ACK. The files are uploaded by chunks sized as configured(defaults to 4 MB).

Plus: It also comes with a file queue mode.

Here is a sample of how you may use it in a Razor View:

$(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();
    });

});

Here's the code for the Upload Action:

[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("");
    }
like image 76
nebtrx Avatar answered Oct 05 '22 19:10

nebtrx