Skip to content

felipekm/upload-mid-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upload Mid Node

Upload Mid Node is a middleware for ExpressJS to handle ´´´multipart/form-data´´´ which basically is used for uploading files.

Installation

$ npm install --save uploadmidnode

Usage

On your routes file include it with require then insert the check function such as:

var upload_mid_node = require('upload-mid-node');

app.post('/upload',

    // Upload middleware check
    upload_mid_node.check({
        options: global.config.public_folders.application.docs,
        supportedFileExt: ['txt', 'doc'],
        multiFiles: true
    }),

    // Next statement
    function (req, res) {
        res.status(200).send(req.uploads);
    }
);

Options:

global.config = {
    public_folders: {
        application: {
            docs: {
                path: "./public/documents",
                limitSize: 20000000
            }
        }
    }
};
  • path: It must contain the physical path which the file will be stored, also it will create a temp which is cleaned after store the files on the final path.
  • limitSize: The file size limit (KB);
  • supportedFileExt: Supported file extensions;

After the middleware route it to the next statement you can access all your uploaded file properties on req.uploads.

Testing

Here is a good place to make calls from a ready web app: Just change the action variable to your local server eg: http://localhost:PORT/upload

Any problem or suggestion get in touch.

License

MIT © Felipe Kautzmann

About

🐪 ExpressJS middleware to handle 'multipart/form-data' requests

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published