version v2.0 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.
- Path handler.
- File naming.
- Upload more then one file in the same request.
- Thumbnails for images & videos.
- S3 support for AWS.
- Upload certain extensions.
- Handling multiple files under the same fieldname.
- ......
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);
});
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
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);
});
This use a uuid v4 library to create the file name
{ filename: 'random' }
This use the name of the uploaded file .
{ filename: 'same' }
This will add after the name of the uploaded file the timestamp when the file uploaded.
{ filename: 'plus_date' }
This use new Date() to create the file name (not prefeared when uploading more then one file)
{ filename: 'date' }
Licensed under MIT
M. Mahrous developed at The D. GmbH Feel free to contact me M. Mahrous and improve the code.