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?
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>
<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!"); } } }); });
$("#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).
$(".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.
Thank you Martin
I've tried your approach and the errorCode in the client returns: nosuchfilekeyid, instead of a code, and the errorMessage also in the client: "The file you requested could not be found. Probably this file is too big." This happens when the file size selected exceeds the max specified in the config: <add key="maxFileSizeLimit" value="1000000" />
On fileUploading, cancelUpload is not fired I suppose for the reasons you said.
Any other tips more than welcome.
Regards