Search code examples
c#asp.net-mvc-3uploadify

Uploadify setting file size limit


I am working on a project i have used uploadify control for file uploading,i have to set file size limit to 5MB, i've seen its documentation Here

I tried setting 5MB but still when i am selecting file around 3MB it is showing file size error I also tried setting value without any unit (ie 5120) but in that case its also showing file size error when i select even of file 3MB size

Here's my code

var sizelimit = '5MB'; //or '5120'
$('#file_upload').uploadify({
        'uploader': ResourceUplodify.Uploader,
        'script': ResourceUplodify.ScriptFile,
        'cancelImg': ResourceUplodify.CancelImg,
        'folder': ResourceUplodify.Folder,
        'fileDesc': 'Document Files',
        'buttonImg': '../../Content/images/Attach-File.jpg',
        'fileExt': '*.pdf;*.doc;*.ppt;*.odt;*.rtf;*.txt',
        // 'sizeLimit': 10485760,
        'sizeLimit': sizelimit,
        'height': 29,
        'width': 90,
        'buttonText': 'Attach File',
        'multi': false,
        'auto': false,
        'onSelect': function (a, b, c, d, e) {          
        },
        'onComplete': function (a, b, c, d, e) {
            //            if (d != '1') {          
        },
        'onError': function () {

        }
    });

I also want to work with session with uploadify,they have shown PHP code for working with session but i dont know how to work with session in C#(using uploadify offcourse)

Working with Session in Uploadify

How can i access value of formdata in MVC3(C# code)


Solution

  • The default request size limit in ASP.NET is 4MB.

    Make sure you have increased the default value of the request size in your web.config using the <httpRuntime> element if you want to allow files larger than 4MB to be uploaded:

    <system.web>
        <!-- 5MD (value is in KB here) -->
        <httpRuntime maxRequestLength="5120" />
        ...
    </system.web>
    

    and also if you are hosting on IIS7 you need to set the maxAllowedContentLength to the same value (in bytes):

    <system.webServer>
        <security>
            <requestFiltering>
                <!-- 5MB (value is in bytes here) -->
                <requestLimits maxAllowedContentLength="5242880" />
            </requestFiltering>
        </security>
    </system.webServer>
    

    As far as the sessions are concerned, you may find the following post useful.