Encoding and Decoding File Attachment Content

The virtual file system (VFS) enables you to store files and internally use references to these files in the message payload. You can also map the VFS file's content to a string element.

For example, you can store files and use references in the VFS as follows:
  • The REST Adapter supports the multipart attachment and application/octet-stream features. The attachment is stored in a staging area and an attachmentReference (string key) is generated. The attachmentReference key is sent as part of the message payload and later fetches the attachment instance from the staging area.

  • The FTP Adapter uses fileReference for reading/writing a file without a schema. fileReference is also a reference to a file stored in the VFS.

In addition, mapping the VFS file's content to a string element enables you to:
  • Map the content of a staged file attachment to a string element by converting the content to a base64 string.

  • Store the base64 string as an attachment and generate a VFS reference.

Two XPath functions are provided to perform these tasks. These functions work with any adapter.

  • encodeReferenceToBase64(String reference): Accepts the VFS’s file reference as input and returns the base64–encoded content of the file as the return value. This function has a file size limit of 10 MB. If a file is larger than 10 MB, an exception message of Maximum file size supported is 10 MB is displayed.

  • decodeBase64ToReference(String base64String): Accepts the base64–encoded content as input, decodes it, stores the base64–decoded value in a file in the VFS, and returns the reference to this file. There is no size limit because the content is already in memory.

The location is the relative path (reference) of the file stored in Oracle Integration Cloud Service. The relative path is one of the following elements:
  • fileReference

  • attachmentReference

  • streamReference

The two XPath functions are available for use in Oracle Integration Cloud Service:
  • Expression Builder, when configuring the following actions in an orchestrated integration:

    • Notification

    • Logging

    • Switch

    • Assign

  • Mapper (visible after selecting Mapping Components - Functions - Advanced):


    Description of encode_decode.png follows
    Description of the illustration encode_decode.png

The attachments are not restricted to document file types. For example, an image can be base64–encoded and later decoded back to the original file.

When an attachment is stored in the VFS, a key is generated to retrieve the attachment at a later time. The key is shown in the mapper as attachmentReference/fileReference/streamReference. This key is propagated within Oracle Integration Cloud Service as part of the payload. The attachment is claimed only when needed. The names attachmentReference, fileReference, and streamReference are based on the adapter type. For example, in the REST Adapter, streamReference is used. The data type of the reference is a string.

With a multipart feature, the HTTP request payload has multiple parts separated by boundaries. Each of the individual parts are considered an attachment. For raw bytes, streamReference is used. FTP uses fileReference.

Sometimes the endpoints accept only base64–encoded values. In these cases, the reference is passed as input to encodeReferenceToBase64 to get the base64–encoded content of the file. Again, the base64–encoded value can be passed as input to decodeBase64ToReference to get the reference (location) to a file that contains the decoded content.