Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
How to Cancel uploading a file on the client
posted

I'm sorry if this was previously asked by obviously the fileUploading event (return false) is not the place to Cancel uploading a file in case any criteria like size is not the expected. What would be the proper way to Cancel from the client uploading files, is that possible on the client or it has to be handled on the server?

Parents
  • 23953
    Offline posted

    Hello elvisvr,

    If you want to cancel file uploading when file size limit is exceeded the best way to do it is this:

    1. Set  "maxFileSizeLimit" setting in the web.config like this:

    <appSettings>

        <add key="fileUploadPath" value="~/Uploads" />

        <add key="maxFileSizeLimit" value="1000000" />

    </appSettings>

    Reference: http://help.infragistics.com/NetAdvantage/jQuery/Current/CLR4.0/Help/NetAdvantage/jQuery/2011.2/CLR4.0/html/igUpload_Using_HTTP_Handler_and_Modules.html

    2. Handle "onError" event on client and check the "ui.errorCode" property for the "File size exceeded" error (Note: error codes are numbers and 2 = "File size exceeded" error).

    Example:

    $("#igUpload").igUpload({

    mode: 'multiple',

    progressUrl: "/SamplesBrowser/IGUploadStatusHandler.ashx",

    controlId: "serverID1",

    onError: function (evt, ui) {

                /* check for "File size exceeded" error*/

    if (ui.errorCode === 2)

    {

    alert("File size exceeded!");

    }

    }

    });

    });

     

    If you have other use case then you should use "cancelUpload" method in the proper event (where you have enough information to do your validation checks).

    Example:

    $(".selector").igUpload("cancelUpload", 1);

    Note that the earliest place you have information about file size is "fileUploading" event, but on this stage file uploading has started so there is no guarantee that file won't be uploaded (if the file is small) and other events will be fired.

     

    Hope this helps,

    Martin Pavlov

    Infragistics, Inc.

Reply Children