1.0.1 • Published 5 years ago

uttori-plugin-upload-multer v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

view on npm npm module downloads Build Status Dependency Status Coverage Status

Uttori Plugin - Multer Upload

A plugin to add file uploading using Multer.

Install

npm install --save uttori-plugin-upload-multer

Config

{
  // Registration Events
  events: {
    bindRoutes: ['bind-routes'],
  },

  // Directory files will be uploaded to.
  directory: 'uploads',

  // Server route to POST uploads to.
  route: '/upload',
}

API Reference

MulterUpload

Uttori Multer Upload

Kind: global class

MulterUpload.configKey ⇒ String

The configuration key for plugin to look for in the provided configuration.

Kind: static property of MulterUpload
Returns: String - The configuration key.
Example (MulterUpload.configKey)

const config = { ...MulterUpload.defaultConfig(), ...context.config[MulterUpload.configKey] };

MulterUpload.defaultConfig() ⇒ Object

The default configuration.

Kind: static method of MulterUpload
Returns: Object - The configuration.
Example (MulterUpload.defaultConfig())

const config = { ...MulterUpload.defaultConfig(), ...context.config[MulterUpload.configKey] };

MulterUpload.validateConfig(config)

Validates the provided configuration for required entries.

Kind: static method of MulterUpload

ParamTypeDescription
configObjectA configuration object.
config[MulterUpload.configKeyObjectA configuration object specifically for this plugin.

Example (MulterUpload.validateConfig(config, _context))

MulterUpload.validateConfig({ ... });

MulterUpload.register(context)

Register the plugin with a provided set of events on a provided Hook system.

Kind: static method of MulterUpload

ParamTypeDescription
contextObjectA Uttori-like context.
context.hooksObjectAn event system / hook system to use.
context.hooks.onfunctionAn event registration function.
context.configObjectA provided configuration to use.
context.config.eventsObjectAn object whose keys correspong to methods, and contents are events to listen for.

Example (MulterUpload.register(context))

const context = {
  hooks: {
    on: (event, callback) => { ... },
  },
  config: {
    [MulterUpload.configKey]: {
      ...,
      events: {
        bindRoutes: ['bind-routes'],
      },
    },
  },
};
MulterUpload.register(context);

MulterUpload.bindRoutes(server, context)

Add the upload route to the server object.

Kind: static method of MulterUpload

ParamTypeDescription
serverObjectAn Express server instance.
server.postfunctionFunction to register route.
server.usefunctionFunction to register middleware.
contextObjectA Uttori-like context.
context.configObjectA provided configuration to use.
context.config.directoryStringThe file path to save files into.
context.config.routeStringThe URL to POST files to.

Example (MulterUpload.bindRoutes(server, context))

const context = {
  config: {
    [MulterUpload.configKey]: {
      directory: 'uploads',
      route: '/upload',
    },
  },
};
MulterUpload.bindRoutes(server, context);

MulterUpload.upload(request, response, next)

The Express route method to process the upload request and provide a response.

Kind: static method of MulterUpload

ParamTypeDescription
requestObjectAn Express request object.
request.fileObjectThe uploaded file.
request.file.filenameStringThe uploaded file's filename.
responseObjectAn Express response object.
nextObjectAn Express next function.

Example (MulterUpload.upload(request, response, _next))

server.post('/upload', MulterUpload.upload);

Tests

To run the test suite, first install the dependencies, then run npm test:

npm install
npm test
DEBUG=Uttori* npm test

Contributors

License