UploadUnit

flitter-upload/UploadUnit~ UploadUnit

Unit representing the flitter-upload package. When run, binds the helper functions and destination.

Constructor

new UploadUnit(upload_directoryopt)

Source:

Initializes the class. Resolves the path to which files should be uploaded.

Parameters:
Name Type Attributes Default Description
upload_directory string <optional>
'./uploads'

Path where files should be uploaded to.

Extends

Methods

(async) cleanup(app) → {Promise.<void>}

Source:
Inherited From:

Cleans up the unit's resources before Flitter closes.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

Returns:
Type
Promise.<void>

(async) delete(file) → {Promise.<void>}

Source:

Deletes an uploaded file and removes its model instance.

Parameters:
Name Type Description
file module:flitter-upload/deploy/File

the File model instance

Returns:
Type
Promise.<void>

(async) deploy() → {Promise.<void>}

Source:

Deploys the resources for flitter-upload. Specifically, the File model which is used to track uploaded files.

Returns:
Type
Promise.<void>

directories() → {Object}

Source:
Inherited From:

Get the directories provided by the unit. Should be an object such that key => value is the name of the directory => fully qualified path to the directory.

Returns:
Type
Object

(async) go(app, context) → {Promise.<void>}

Source:
Overrides:

Loads the unit. Binds the handler functions to the context and global accessors.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp
context module:libflitter/Context~Context
Returns:
Type
Promise.<void>

name() → {string}

Source:
Overrides:

Get the name of the unit.

Returns:

"upload"

Type
string

serve(res, file)

Source:

Sends the file with the specified UUID as a response to the user.

Parameters:
Name Type Description
res Response

the Express response

file module:flitter-upload/deploy/File

the File model instance

upload(file, typeopt) → {function}

Source:

Get the Express middleware to upload the file in the specified input name. File is saved with a UUID name in module:flitter-upload/UploadUnit~UploadUnit#directory.

Optionally, a type may be specified. These are strings used to categorize the files so they can be used in groups. They have no effect on functionality.

Parameters:
Name Type Attributes Default Description
file string

name of the input field containing the file

type string <optional>
'none'

type to flag the file with

Returns:
  • Express-compatible middleware
Type
function