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
What I found is that this error is returned when the file exceeds maximum upload file size which is 2GB. This limitation is described in "igUpload Known Issues" document which you can find here:
http://help.infragistics.com/NetAdvantage/jQuery/Current/CLR4.0/Help/NetAdvantage/jQuery/2011.2/CLR4.0/html/igUpload_Known_Issues.html
Is this your case?
If not, can you provide me with more information like:
Is there an error in your sentence "On fileUploading, cancelUpload is not fired I suppose for the reasons you said.". "cancelUpload" is method, not event. What is your code in "fileUploading" event?
Thank you Martin for your help, the file I'm trying to upload is just 700MB and the settings on the we.config are the following:
<add key="maxFileSizeLimit" value="100000000" />
<add key="bufferSize" value="16384" />
<add key="allowedMIMEType" value="*" />
Hello Elvis,
I reproduced your problem and after further investigation I found the following:
If you're using IIS 7 there is a file size limit setting which is described here:
http://support.microsoft.com/kb/942074/ and here:
http://www.webtrenches.com/post.cfm/iis7-file-upload-size-limits
Because I use IIS Express for my test server the change I made in my application web.config is the following:
<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"> <add name="IGUploadModule" type="Infragistics.Web.Mvc.UploadModule" preCondition="managedHandler" /> </modules> <handlers> <add name="IGUploadStatusHandler" path="IGUploadStatusHandler.ashx" verb="*" type="Infragistics.Web.Mvc.UploadStatusHandler" preCondition="integratedMode" /> </handlers> <security> <requestFiltering> <requestLimits maxAllowedContentLength="1073741824"/> </requestFiltering> </security> </system.webServer>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<add name="IGUploadModule" type="Infragistics.Web.Mvc.UploadModule" preCondition="managedHandler" />
</modules>
<handlers>
<add name="IGUploadStatusHandler" path="IGUploadStatusHandler.ashx" verb="*" type="Infragistics.Web.Mvc.UploadStatusHandler" preCondition="integratedMode" />
</handlers>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"/>
</requestFiltering>
</security>
</system.webServer>
Note that in my case I set "maxAllowedContentLength" to be 1GB.
If you're using IIS 6 then you may want to look at this blog post:
http://weblogs.asp.net/mhawley/archive/2004/05/11/129824.aspx
If this solution doesn't work in your case then you may want to check this post suggestions for common errors:
http://blogs.infragistics.com/forums/p/57050/293106.aspx#291612
Best Regards,
Thank you very much Martin with your last post and handling the files sizes on the server event: webUpload1_UploadStarting I'm really happy with the control.
Best Regards
Elvis
Great! :)
You are welcome.
Good luck with your application.
All Best,