You are viewing limited content. For full access, please sign in.

Question

Question

Forms calculate total attachment file size

asked on January 26, 2023

We have a Forms business process that results in an email being sent to our customer.  The issue that we are running into is that on occasion they will attach to many or to large of files that result in an email send failure due to the total attachment file size.  Has anyone had any luck with calculating the total file size of all attachments and not allowing the submission if that total exceeds a preset limit?

0 0

Replies

replied on January 26, 2023 Show version history

This worked for me on the Classic Designer on Forms version 11.0.2212.30907.

This works by adding a new parsley validation to the upload field that totals the size of all attached files, and if it exceeds the size, it'll give the error.  To set it up, give your upload field(s) the CSS Class Name of maxUploadSize, and then set the max size in the Javascript on line 4.  The only thing I could never get working was to have it validate as soon as the upload happens instead of at form submission.

$(document).ready(function() {
  
  //Set the max file size for the upload validation (in MB).
  var maxTotalFileSizeAllowed = 5;
  
  //Add parsley validator for max total file size of uploaded files.
  window.Parsley.addValidator('maxtotalfilesize', {
    validateString: function(value, requirement, parsleyField) {
      var totalSize = 0;
      parsleyField.$element.parent().find('.files .imgSize').each(function() {
        var length = $(this).attr('title').toString();
        var size = parseFloat(length.substring(0, length.length - 2));
        var scale = length.substring(length.length - 2);
        if(scale == 'KB') { size = size * 1024; }
        else if(scale == 'MB') { size = size * 1024 * 1024; }
        else if(scale == 'GB') { size = size * 1024 * 1024 * 1024; }
        else if(scale == 'TB') { size = size * 1024 * 1024 * 1024 * 1024; }
        totalSize = totalSize + size;
      });
      return totalSize <= parseFloat(requirement * 1024 * 1024);
    },
    messages: {
      en: 'The total size of all files uploaded should not exceed ' + maxTotalFileSizeAllowed + ' MB.'
    }
  });
  
  //Add the custom parsley validation to the file upload that has the maxUploadSize class.
  $('.maxUploadSize input').attr('data-parsley-maxtotalfilesize', maxTotalFileSizeAllowed);
  
});

1 0
replied on January 17, 2024

FYI - I believe built-in functionality to do this in the new designer was added in Forms 11 Update 5...

0 0
replied on January 26, 2023

Hello Glenn,

 

I found another post with a similar question that has a couple of solutions:

 

https://answers.laserfiche.com/questions/163898/File-Upload--Maximum-TOTAL-file-size

 

Regards,

Travis

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.