readFiles()

The readFiles() function (client-side) retrieves information for all files attached to a file question. You can use this function when a configuration step collects uploaded files (like images or documents) and your script needs to process, store, or forward those files.

Syntax

This is the general this syntax for the readFiles() function:

            readFiles(questionCode, encodingOptions).done(callback); 

          

See detailed information about the syntax for each parameter:

            readFiles('QUESTION_CODE', {
    encoding: 'base64' | 'text'
}).done(callback); 

          

Return Value

The readFiles() function returns a promise that resolves to an array of objects. Each object in the array represents a single file. The returned array has the following structure:

            [
  {
    type: "",
    name: "",
    content: ""
  },
  {
    type: "",
    name: "",
    content: ""
  },
  // ...
] 

          

Parameters

Note:

The question code is required.

The readFiles() function accepts the following parameters:

  • QUESTION_CODE (string) - Specifies the code of the question from which to read the files. You can find it in the Code field on the question record.

  • encodingOptions (Object) - Supports an encoding property that accepts the following values:

    • text - Returns the content of the file as a readable string. This is the default value.

    • base64 - Returns the content of the file as a Base64-encoded string. You can use this option for binary files, such as an image or a zipped file.

Examples

The following examples show how to use the readFiles() function.

Retrieving Files As Base64

This example reads all files attached to the question with the code CUSTOMIZATION_SUGGESTIONS. It requests base64 encoding so binary content can be safely handled as a string.

              await readFiles('CUSTOMIZATION_SUGGESTIONS', {
    encoding: 'base64'
}); 

            

The result is an array in which each element contains the file metadata and encoded content.

              [
    {
        "type": "image/png",
        "name": "Desk customization suggestions.png",
        "content": "iVBORw0KGgoAAAANSUhEUgAA"
    }
] 

            

Related Topics

General Notices