Prevent users from uploading large files in web forms

Version: 8.1

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:

  1. In Visual Studio, create a new processor class specifying the file size limit:

    RequestResponse
    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();
          }
        }
      }
    
  2. Register the new processor in the Sitecore.Forms.config file:

    RequestResponse
    <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.

Do you have some feedback for us?

If you have suggestions for improving this article,