0
votes

I am trying to implement file attachment to my AEM Form. The idea is to embed the attachment to the PDF; Upon submission of the PDF, the backend system will be able to extract the attached file from the PDF.

I can't seem to find any example on how I can go about doing it, which make me wonder is it a limitation. However, on adobe site below, it is actually stated "Support for file attachments" for all AEM form types.

https://helpx.adobe.com/aem-forms/6/introduction-aem-forms.html

Please advice! Thanks!

2

2 Answers

0
votes

You can upload, preview, and submit attachments with HTML5 forms. By default, the attachment support is disabled. To enable the attachment support:

1- Create a custom profile with mutiselect string property mfAttachmentOptions.

2- In the custom profile, specify properties fileSizeLimit, multiSelect, and buttonText to configure options of the file attachment widget. As required, you can also specify more custom properties.

3- In the custom profile, use the following configurations:

  • multiSelect -> true or false (true by default)
  • fileSizeLimit -> value_in_mb (say 5) (2 MBs by default)
  • buttonText -> Button text for pop-up window ("Attach" by default)
  • accept -> file types to accept ("audio/, video/, image/, text/, .pdf" by default)

4- Use the metadata editor to select the custom profile that you have created above for HTML 5 forms.

5- Render your form template with custom profile and the attachments icon would appear on the forms toolbar.

6- Click the attachment icon, an attachment selection dialog box appears. Browse and select the attachment and click Attach.

When attachments are enabled, HTML5 form submits multipart data. The mutli-part submission data has two parts dataXml and attachments.

Reference: https://helpx.adobe.com/aem-forms/6-1/html5-forms/enabling-attachments-html5-form.html

0
votes

Below is the code for "Add Attachment" button.

var oDoc = event.target;
var doccount = parseInt(colhead.attcount.rawValue);
colhead.attcount.rawValue = doccount + 1;
Trusted_ImportDataObject(oDoc, doccount);
var oAttachment = oDoc.getDataObject("attachment_" + doccount);
var DOsize = oAttachment.size;
var DOmimeType = oAttachment.MIMEType;
if (DOmimeType == null) DOmimeType = "reject";
if ((DOsize > 1100000) || (DOmimeType.indexOf("image/") != 0)) {
    xfa.host.messageBox("Attachemtns must be an image and smaller than 1 Megabyte");
    oDoc.removeDataObject("attachment_" + doccount);
} else {    
    var attachPath = oAttachment.path;
    AttachFileName.rawValue = attachPath;
    AttachMIMEType.rawValue = oAttachment.MIMEType;
    AttachHref.rawValue = oAttachment.name;
}

Do note that Reader Extension is needed to enable file attachment. Else you will be getting this error:

NotAllowedError: Security settings prevent access to this property or method.
Doc.importDataObject:6:XFA:CTR[0]:Page6[0]:part6[0]:body[0]:attachitem[0]:AddAttachment[0]:click