mm-file

1.2.0 • Public • Published

Matter In Motion. File uploads and processing resource extension

NPM Version NPM Downloads

This extension adds a file resource.

Usage

Extensions installation instructions.

This extension validates file type before downloading file.

File upload

You can upload files via FormData.

Settings

  • defaults — object, any default options. Will be applied to the jobs.
  • jobname — object, job declaration
    • to — string, default filename. Will be applied if action options doesn't have the to option
    • limit — number, maximum files to be accepted
    • accept — array, list of the mime types accepted by this job
    • do — array, list of action to be applied to each file
      • { 'processor:action': {options}} — action with its options.

Settings example:

this.file = {
  defaults: {
    root: this.join('static', 'uploads') // files storage root.
  },
 
  test: {
    accept: [ 'image/jpeg' ],
    do: [
      { 'fs:copy': { name: 'copy', to: '{filename}_{copy}{_#}{ext}' } }
    ]
  }
};

Processor action options

All actions have only two common options: name and to.

Path patterns

The following curly bracket variables can be used in the to option:

  • fieldname — field name from form data
  • filename — original file name
  • ext — original file extension
  • name — action name
  • year — four digits year
  • month — the padded (ex. 01) number, 1-based
  • day — the padded number, 1-based
  • # — unique file pattern read more about it here

plus any data that particular processor accepts with the files.

Safe

All generated file paths and names are sanitized. You can upload files with names in any encoding supported by JavaScript.

File processors

  • fs — built-in processor with the following methods:
    • copy copies file
    • move moves file
    • delete deletes file
  • image — super fast image processor with animated GIF support

For processors methods and options go to processors docs.

API

process

Processes the file or files with the job

Request

All files and any other data should be sent as FormData.

  • job — job name to use for files

Respond

Depends on the processors used in the job.

License: MIT.

Package Sidebar

Install

npm i mm-file

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

15.2 kB

Total Files

12

Last publish

Collaborators

  • velocityzen