The Upload Unit

flitter-upload/UploadUnit

exports:  class UploadUnit

class UploadUnit

extends:  libflitter/Unit

Creates a middleware function that uploads files based on the field name.

directory

type:  String

The fully-qualified path to the folder where files should be uploaded.

constructor(String upload_directory = './uploads')

returns:  this

Initializes the class. Resolves the upload_directory and stores it in this.directory.

go(express app, function next)

returns:  undefined

Loads the unit. Creates  the _flit.uploads object and helper functions. This establishes the Upload context and calls the next function in the stack under it.

upload(String file)

returns:  function

Returns an Express middleware function that uploads the file provided in req.files[file] to this.directory and creates an instance of flitter-upload/deploy/File in req.files[file], then calls the next function in the stack. If a uploaded file by that name doesn't exist, the middleware does nothing and calls the next function.

serve(express.response res, flitter-upload/deploy/File file)

returns:  undefined

Serves the file as the response to the user.

delete(flitter-upload/deploy/File file, function callback)

returns:  undefined

Deletes the specified file from the disk and removes its record. Then the callback is executed. If an error occurs, it is passed to the callback.

deploy(function callback)

returns:  undefined

Runs the deployment for this unit. Copies the flitter-upload/deploy/File.model.js file to models/upload/File.model.js, then the callback is executed. If an error occurs, it is passed to the callback.

Upload Context

_flit.uploads

type:  Object

Holds the variables and functions provided by this unit.

_flit.uploads.upload(String file)

type:  function

Mapped to this.upload(). Should be called as middleware on the route of the file upload submission.

_flit.uploads.serve(express.response res, flitter-upload/deploy/File file)

type:  function

Mapped to this.serve(). Can be called from within a controller to serve an uploaded file.

_flit.uploads.destination

type:  String

Fully-qualified path to the folder where uploaded files are stored.

_flit.uploads.model

type:  mongoose/Model

The reference to the flitter-upload/deploy/File model. Used to access and store new file records.

_flit.uploads.remove(flitter-upload/deploy/File file, function callback)

type:  function

Mapped to this.delete(). Removes the file from disk and deletes its record.

_flit.upload(String file)

type:  function

Mapped to _flit.uploads.upload.

deployment:  upload

Moves flitter-upload/deploy/File.model.js to models/upload/File.model.js.

No Comments
Back to top