lib/backend/deprecated/controllers/file-controller.js
//save a file (type=file need to be the last item of the form.)
save a file (type=file need to be the last item of the form.)
save a file ( type = file need to be the last item of the form . )
function save(data, cb, req, res) {
    logger().debugTerminal('save:start=' + JSON.stringify(data));
    if (req.busboy) {
        var requiredFileds = ['name', 'mimetype', 'file'];
        var interval = setInterval(() => {
            var success = true;
            requiredFileds.forEach((k) => {
                if (!data[k]) {
                    logger().debugTerminal('save:waiting for property ' + k + ' in data.');
                    success = false;
                }
            });
            if (success) {
                clearInterval(interval);
                _streamToDb(data, cb);
            }
        }, 1000);
        req.busboy.on('field', function(key, value, keyTruncated, valueTruncated) {
            data[key] = value;
        });
        req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
            data.file = file;
            data.mimetype = mimetype;
        });
        req.pipe(req.busboy);
    }
    else {
        logger().debugTerminal('save:error= busboy required.');
        return cb('busboy requried', null);
    }
}
function save ( data , cb , req , res ) { logger ( ) . debugTerminal ( 'save:start=' + JSON . stringify ( data ) ) ; if ( req . busboy ) { var requiredFileds = [ 'name' , 'mimetype' , 'file' ] ; var interval = setInterval ( ( ) => { var success = true ; requiredFileds . forEach ( ( k ) => { if ( ! data [ k ] ) { logger ( ) . debugTerminal ( 'save:waiting for property ' + k + ' in data.' ) ; success = false ; } } ) ; if ( success ) { clearInterval ( interval ) ; _streamToDb ( data , cb ) ; } } , 1000 ) ; req . busboy . on ( 'field' , function ( key , value , keyTruncated , valueTruncated ) { data [ key ] = value ; } ) ; req . busboy . on ( 'file' , function ( fieldname , file , filename , encoding , mimetype ) { data . file = file ; data . mimetype = mimetype ; } ) ; req . pipe ( req . busboy ) ; } else { logger ( ) . debugTerminal ( 'save:error= busboy required.' ) ; return cb ( 'busboy requried' , null ) ; } }
save a file (type=file need to be the last item of the form.)
save a file ( type = file need to be the last item of the form . )
//console.log('save:field=', key, value, keyTruncated, valueTruncated); //console.log('save:file=', fieldname, inspect(file), filename, encoding, mimetype); //console.info('query',req.query); //console.info('params',req.params); //console.info('body',req.body);