Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

validate the file type, size when adding an attachment to PDF

Avatar

Level 2

Hi all,

I have issues for creating a attachment button. I have validated the file type (e.g. pdf, doc, tiff, ect.) and total size is less than 9MB when adding files to PDF. When I select the attachment button to add the file, the total size is not add everytime I add the file. It is only display of each file. I cannot figure out why is coding is not working. I have spent two days to work on it but unsucessful.

I have attached the testing form. It is easy for you to follow.

I place coding in event:click under attachment button.

Here is my coding:

 

var oObj = event.target;
var aTotal;
var cFiles = oObj.dataObjects;
var counter = 0;
var nTotalSize;
var nTotalKb = "83886080"  //.......... kilobytes

if(attachmentsList.length > 0)
{
 
  oObj.importDataObject(cFiles.length);
  var oDataObj = oObj.getDataObject(cFiles.length);
  attachmentsList.addItem(oDataObj.path);
 
  NoOfAttachments.rawValue = cFiles.length+1;
 
 
 
  aTotal = (cFiles.length)
  aTotal =  oDataObj.size
  FileSize.rawValue = aTotal;
 
AttachmentDescription.rawValue;
var cFiles = AttachmentDescription.rawValue;
var oObj = event.target;
//oObj.removeDataObject(cFiles);
//oObj.importDataObject(cFiles);



//oObj.importDataObject(cFiles);
//var oDataObj = oObj.getDataObject(cFiles);
//
var fileName = oDataObj.path;

var fileType = fileName.substring(fileName.lastIndexOf("."));

attachmentsList.rawValue = fileName;

if(fileType != ".pdf" && fileType != ".PDF" && fileType != ".JPG" &&
  fileType != ".jpg" && fileType != ".tif" && fileType != ".TIF"&&
  fileType != ".tiff" && fileType != ".TIFF"){
  xfa.host.messageBox("Incorret Document");
  oObj.removeDataObject(cFiles);
  }


  }

else
{

oObj.importDataObject(counter.value);
var oDataObj = oObj.getDataObject(counter.value);
  attachmentsList.addItem(oDataObj.path);
NoOfAttachments.rawValue = 1;

 


}

Thanks for your help.

Cindy

0 Replies