Namespace: APIUploadHandler

APIUploadHandler

Process uploads via the API.

Source:

Methods

(static) addMetadata(files, fileRevs, data) → {Array.<File>}

Add all metadata to each file revision (does not save)

Parameters:
Name Type Description
files Array.<Object>

file objects received from the middleware

fileRevs Array.<File>

initial revisions of the File model, containing only the data that comes with the file itself (MIME type, filename, etc.)

data Ojbect

request data

Source:
Returns:

the revisions for further processing

Type
Array.<File>

(static) addMetadataToFileRev(file, fileRev, data, optionsopt)

Add all relevant metadata to an individual file revision

Parameters:
Name Type Attributes Description
file Object

file object from the middleware

fileRev File

initial revision of the File model

data Object

request data

options Object <optional>

Validation options

Properties
Name Type Default Description
addSuffix Boolean false

Add a filename suffix to each field (used for requests with multiple files)

Source:

(static) apiUploadHandler(req, res) → {function}

The main handler for processing upload attempts via the API. Kicks in after the basic MIME check within the Multer middleware. Handles metadata validation & creation of "File" revisions.

Parameters:
Name Type Description
req IncomingMessage

Express request

res ServerResponse

Express response

Source:
Returns:

callback invoked by the Multer middleware

Type
function

(static) checkRequired(obj, requiredopt, conditionallyIgnoredopt) → {Array.<Error>}

Check if we have "truthy" values for all required fields in a given object (typically an API request body). Also throws errors if given fields are present with a "truthy" value, which is useful for conflicting parameters that may be submitted with empty values.

Parameters:
Name Type Attributes Default Description
obj Object

any object whose keys we want to validate

required Array.<String> <optional>
[]

keys which must access a truthy value

conditionallyIgnored Array.<String> <optional>
[]

keys which will be ignored unless they access a truthy value

Source:
Returns:

errors for each validation issue or an empty array

Type
Array.<Error>

(static) reportUploadSuccess(req, res, fileRevs)

Send a success response to the API request that contains the newly assigned filenames, so they can be used, e.g. in the editor.

Parameters:
Name Type Description
req IncomingMessage

Express request

res ServerResponse

Express response

fileRevs Array.<File>

the saved file metadata revisions

Source:

(static) validateAllMetadata(files, data) → {Array.<Error>}

Ensure that required fields have been submitted for each upload.

Parameters:
Name Type Description
files Array.<Object>

Files to validate

data Object

Request data

Source:
Returns:

Validation errors, if any.

Type
Array.<Error>

(static) validateMetadata(file, data, optionsopt) → {Array.<Error>}

Check that required metadata fields are present for a given upload. Also ensures that language is valid, and that license is one of the accepted licenses.

Parameters:
Name Type Attributes Description
file Object

File received from the upload middleware

data Object

Request data that should contain the metadata we need

options Object <optional>

Validation options

Properties
Name Type Default Description
addSuffix Boolean false

Add a filename suffix to each field (used for requests with multiple files)

Source:
Returns:

Validation errors for this field, if any

Type
Array.<Error>