2.3.0 • Published 2 years ago

@uttori/plugin-upload-multer v2.3.0

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

view on npm npm module downloads Build Status Coverage Status dependency status npm bundle size

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',

  // Server route to GET uploads from.
  publicRoute: '/uploads',

  // Custom Middleware for the Upload route
  middleware: [],
}

API Reference

Classes

Typedefs

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() ⇒ MulterUploadConfig

The default configuration.

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

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

MulterUpload.validateConfig(config, _context)

Validates the provided configuration for required entries.

Kind: static method of MulterUpload

ParamTypeDescription
configobjectA configuration object.
_contextobjectUnused.

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.

Example (MulterUpload.bindRoutes(server, context))

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

MulterUpload.upload(context) ⇒ RequestHandler

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

Kind: static method of MulterUpload
Returns: RequestHandler - The function to pass to Express.

ParamTypeDescription
contextobjectA Uttori-like context.
context.configobjectA provided configuration to use.

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

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

MulterUploadConfig : object

Kind: global typedef
Properties

NameTypeDescription
eventsobjectEvents to bind to.
directorystringDirectory files will be uploaded to.
routestringServer route to POST uploads to.
publicRoutestringServer route to GET uploads from.
middlewareArray.<RequestHandler>Custom Middleware for the Upload route

Tests

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

npm install
npm test
DEBUG=Uttori* npm test

Contributors

License

2.3.0

2 years ago

2.2.1

2 years ago

2.2.0

3 years ago

2.1.1

3 years ago

2.0.4

3 years ago

2.1.0

3 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago