[ws] Unifi attachmentswhich detects newly inserted attachments (it does not run for x_snd_eb tables). This after insert rule creates Bonded Attachment (BA) records as required by calling
Message.processOutboundis called against the target record, with an option that indicates that this was as a result of an attachment being added.
AttachmentHandler#getAttachmentsToSend, called from
Transaction#sendmethod will create a new request and call
Message#generatePayload. This method processes the
Stage to Request (Outbound)script, if present, and if that returns no payload then the XML template will be processed.
<snd_eb_attachments>which finds each Bonded Attachment in the Sending state, embeds an attachment placeholder for each one into the payload, and sets the BA to the Sent state (the UI Macro is part of "[ws] Unifi Standard API" application).
<x-attachment-data>elements. There will be one element per attachment returned and it will contain the sys_id of sys_attachment to be sent.
AttachmentSenderis essentially an iterator over all BA records for a specific transaction where the state is Sending. It marks each BA as Sent once it has been selected
HttpRequest#sendwhich calls the static method
AttachmentHandler.injectAttachments. This replaces the
<x-attachment-data>elements with Base64 data. This behaviour is hard-coded.
extract_attachmentsscript is called
snd_eb_api_utils.extractAttachmentsscript expects an XML document or string as input and searches for an element called
eb:Attachmentelements which each have
eb:Datachild nodes. The text content of these are read and stored in a
resultobject. The text content of the Data element is removed from the input XML (so when it is passed back we can log the inbound request_payload without the attachment data).
AttachmentHandler.saveAttachment(with the raw Base64 data already decoded). This method creates the attachment and links it to the HTTPRequest record (note that this will not trigger the after insert rule on the Attachments table, since HTTPRequest is an x_snd_eb type table). The method is expected to return an
x-attachment-datatag containing the sys_id of the attachment created as an attribute. This tag is inserted into the original XML.
x-attachment-dataplaceholder tags substituted for the raw attachment data.
AttachmentHandler.createInboundAttachmentsscript expects to process a
x-attachment-dataplaceholders embedded within. The sys_ids of these placeholders are extracted using regex search, and for each sys_id we call
AttachmentHandler.addToTransaction, which creates a Bonded Attachment in the Ready state (There will be no Bond specified on the BA at this point).
x-attachment-dataplaceholder tags is hard-coded into Unifi.