My clients requested the form has the validation when I add attachments to a PDF, the total sizes of these atttachments 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 unsucessful. Please help!!!!
Thank you very much.
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");
}
because of the base64 encoding the string length is different to the binary data stream length.
The factor is around 3/4 so when you use
radzmar
• LoveCycle Blog
Documents you need:
• LiveCycle Designer ES2 Docs