Interface methods

Use interface methods to manage attachments.

Table 1. Interface methods and descriptions
Interface method Description
createAttachment(ctx) Called to create an attachment in the store. Code uses the ctx to get the file name.
  • ctx.getAttachmentName derives the full path-based file name
  • ctx.getFileName(..) extracts the file name out of it.
  • ctx.getAttachmentData() returns the attachment as a byte array.
deleteAttachment(ctx) Called to delete the attachment from the store. Use the same methods as applicable for createAttachment(ctx) to obtain the file name and use it as a key to delete the file from the store.
getAttachment(ctx) Called to get the attachment. Two scenarios are possible, which the code must address:
  • The ctx has the doclinks mbo. Use it to get the file name to fetch ctx.getFileName(ctx.getMbo().getString("urlname")).
  • The ctx just has the URL name for the attachment. use ctx.getFileName(ctx.getURLForAttachment()).
Leverage the file name to retrieve the attachment from the store and then set the attachment data as bytes into the ctx, that is, ctx.setAttachmentData(..)
hasAttachment(ctx) Called for validation the attachment file type from the file name and to check whether the file name is unique. Use the ctx to get the file name through ctx.getFileName(ctx.getAttachmentName()). Use this file name to check for duplicate names in the store. If a duplicate exists, rename the file in context to make it unique, and prefix it with the mxe.doclink.doctypes.topLevelPathsproperty value to create a qualified name.