Expand my Community achievements bar.

check the total sizes of total attachments not allow more than 9 mb when adding attachments to a PDF

Avatar

Level 2

My clients requested the form has the validation when I add attachments to a PDF, the total sizes of these  attachments not more than 9 Mb. I can just check the size of each attachment but I cannot check the total sizes of the attachment.  I am not sure what I am doing wrong the coding is unsuccessful.  Please help!!!! 

Thank you very much.

CindyWhat

Here is the coding in event:click - attachment button

var maxSize=75497472; //bits

try{
var count= 0;
var oDoc = event.target;
var oAttachment = oDoc.dataObjects;
if(oAttachment != null){
 
  count = oAttachment.length;

}


oDoc.importDataObject("attachment" + (count + 1))
var dataObj = oDoc.getDataObject("attachment" + (count + 1));

var fileName = dataObj.path;
var fileType = fileName.substring(fileName.lastIndexOf("."));
  if(fileType != ".pdf" && fileType != ".PDF" && fileType != ".JPG" &&
  fileType != ".jpg" && fileType != ".tif" && fileType != ".TIF"&&
  fileType != ".tiff" && fileType != ".TIFF" &&
  fileType != ".doc" && fileType != ".DOC"){
                xfa.host.messageBox("Please correct the file type.");
                oDoc.removeDataObject("attachment" + (count + 1));


        }
       

// combine size

  //get content
  var oFile = oDoc.getDataObjectContents("attachment" + (count + 1), true);
 
                        var oBase64Stream = SOAP.streamEncode(oFile, "base64");
                      var oFile = SOAP.stringFromStream(oBase64Stream);

                        // check the length of the document
                        var lenTotal = oFile.length;
                        FileSize.rawValue = lenTotal;
                       
                      
                      
  if (lenTotal > maxSize)
  {
   xfa.host.messageBox("the total size is 9 MB");
   oDoc.removeDataObject("attachment" + (count + 1));
  }// end if
  else
  {
   xfa.host.messageBox("successfull attachment","Attachment",2);
  }

}
                              
catch (e)
{

xfa.host.messageBox("Please review the document");
}

 

0 Replies