简体   繁体   中英

how to upload video bigger than 25 mb- c#, javascript

I have a problem with uploading video in my project. If File has about 25mb then uploads good, but if I try to upload bigger file - 80 mb, I receive "failed".

Web.config file:

<httpRuntime maxRequestLength="104857600" executionTimeout="3600" />

My function in view file:

function createVideoUploader() {
        videoTempName = '@Guid.NewGuid().ToString().Replace("-", "").Substring(0, 13)';
        var uploader = new qq.FileUploader({
            element: document.getElementById('video-uploader'),
            allowedExtensions: ['3g2', '3gp', 'avi', 'f4v', 'flv', 'm4v', 'mov', 'mp4', 'mpeg', 'mpg', 'mts', 'ogv', 'webm', 'wmv'],
            sizeLimit: 838860800, //304857600,
            action: '@Url.Action("Upload", "Upload")',
            params: { 'fileTempName': videoTempName },
            multiple: false,
            onSubmit: function (id, fileName) {
                $('div.qq-upload-button').hide();
                $(".qq-upload-drop-area").remove();
            },
            onCancel: function() {
                createVideoUploader();
            },
            onComplete: function (id, fileName, responseJSON) {
                if(responseJSON.success == false) {
                    uploaded = false;
                    $("#videoUploadedFail").show(); // show video error
                    var postData = { 'fileTempName': videoTempName };
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Action("DeleteTemp", "Upload")',
                        data: $.param(postData,true),
                        async: false
                    });
                } else if(responseJSON.success == true) {
                    uploaded = true;
                    $('div.qq-upload-button').hide();
                    var postData = { 'fileTempName': videoTempName };
                    $.post("@Url.Action("PreprocessVideo", "Upload")", $.param(postData,true),
                        function (data) {
                            appendSuccess("#flowVideo");
                            totalTime = secsToTime(data.seconds); // seconds to time
                            $("#duration").html(totalTime);
                            $(".timeText").html(totalTime);
                            $("#orderSlides").css("display", "inline-block");
                        });
                  }
            }
        });
        if (!($.browser.msie))
            $('span.qq-upload-span').append(' or drop file here');
    }

IIS 7+ now requires you to also set the newer requestFiltering/requestLimits/maxAllowedContentLength attribute, and this has a default value for maxAllowedContentLength of 30000000 (which is approximately 28.4MB) which would fit with what you are seeing.

This should be set in conjunction with the httpRuntime/maxRequestLength attribute to ensure that both IIS (via maxAllowedContentLength in bytes) and ASP.NET (via maxRequestLength in kilobytes) are in agreement.

You should be able to change this via the requestLimits element of your applications web.config to allow a more appropriate maximum:

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

One thing to bear in mind though is that this is request filtering is performed server-side, once the content length has exceeded the limit - so there's nothing to stop the user attempting to upload a 150MB only to have it fail once 100.1MB have been uploaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM