Prevent users from uploading large files in web forms
Abstract
Prevent site visitors from uploading files larger than a certain size in web forms.
In the Web Forms for Marketers module, you can prevent users from using the File Upload form field to upload files larger than 10 MB.
To prevent users from uploading large files using the File Upload field:
In Visual Studio, create a new processor class specifying the file size limit:
using Sitecore.Form.Core.Pipelines.FormUploadFile; public class UploadingLimitation { public void Process(FormUploadFileArgs args) { int size = 10485760; // == 10 Mb if (args.File.Data.Length > size) { Sitecore.Diagnostics.Log.Info(string.Format("User {0} tried to upload a file larger than 10 Mb. The file name is {1}", Sitecore.Context.User.Name, args.File.FileName), this); args.AbortPipeline(); } } }
Register the new processor in the
Sitecore.Forms.config
file:<formUploadFile> <processor type="YourNamespace. UploadingLimitation, YourAssemblyName"/> … </formUploadFile>
After you implement the solution, users cannot upload files larger than 10 MB, and the corresponding message is saved to the log files.