I'm trying to change the flow from using callbacks to promises, so far this is what I had done: Using bluebird:
var q = require('bluebird');
var busboy = q.promisifyAll(require('connect-busboy'));
Normally using callbacks what I do is the following
req.busboy.on('file',function(fieldname, file, filename, encoding, mimetype){
console.log('uploading file:'+mimetype);
file.on('data',function(data){
console.log('gettting data ');
});
file.on('end', function(){
console.log('file end');
});
}
What I'd like to do is the following:
req.busboy.on('file').then(function(fieldname, file, filename, encoding, mimetype){
console.log('uploading file:'+mimetype);
file.on('data').then(function(data){
console.log('gettting data ');
}).on('end').then(function(){
console.log('file end');
});
});
I'm getting the following error:
Object # has no method 'then'