You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

multi-rest

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multi-rest

A middleware to handle multi-part request for restify

1.4.2
Source
npmnpm
Version published
Weekly downloads
36
500%
Maintainers
1
Weekly downloads
 
Created
Source

Multi Rest v1.4

version v1.4 has a back compatibility with old version but prefered to update

Multi rest is a swiss knife for handling multi-part requests for restify , and as all nodejs framework is use http server at the end so I built this as if I'm dealing with http request, this module can handle diffrent file and process them.

Features:

- Path handler.
- File naming. 
- Upload more then one file in the same request. 
- Thumbnails for images & videos.
- S3 support for AWS.
- Upload certain extensions.

In progress

- Handling multiple files under the same fieldname.
- ......

NPM

Example for disk:


const restify = require('restify');
const Multi = require('multi-rest');

var server = restify.createServer();

var upload = new Multi({ 
					uploadDir: "./uploads/", 
					filename: 'random', 
					filefields: ['video'], 
					extensions: ['mp4'],
					thumbnail: {type: 'video'}, 
					used: 'maybe'});

server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.CORS());

server.post('/upload', upload ,function (req, res, next){
	res.send({success: true, files: req.files, message: "file uploaded :)"});
});

server.listen(8080, function() {
  console.log('%s listening at %s', server.name, server.url);
});

Example for s3:

check how to configure AWS-SDK for Nodejs

You need to create AWS credentials to ~/.aws/credentials

[default]

aws_access_key_id = your_access_key

aws_secret_access_key = your_secret_key

Test code:


const restify = require('restify');
const Multi = require('multi-rest');

var server = restify.createServer();

var upload = new Multi({driver: { type: 's3', 
						endpoint: 's3-accelerate.amazonaws.com', 
						signatureVersion: 'v4', 
						region: 'eu-central-1', 
						bucketName: 'bucketName'
					}, 
					uploadDir: "uploads/", 
					filename: 'random', 
					filefields: ['video'], 
					extensions: ['mp4'],
					thumbnail: {type: 'video'}, 
					used: 'maybe'});

server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.CORS());

server.post('/upload', upload ,function (req, res, next){
	res.send({success: true, files: req.files, message: "file uploaded :)"});
});

server.listen(8080, function() {
  console.log('%s listening at %s', server.name, server.url);
});

File naming

Random

This use a uuid v4 library to create the file name

{ filename: 'random' }
Same name

This use the name of the uploaded file .

{ filename: 'same' }
Plus date

This will add after the name of the uploaded file the timestamp when the file uploaded.

{ filename: 'plus_date' }
Date

This use new Date() to create the file name (not prefeared when uploading more then one file)

{ filename: 'date' }

License

Licensed under MIT

Author

M. Mahrous Feel free to contact me M. Mahrous and improve the code.

Keywords

restify

FAQs

Package last updated on 17 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts