Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var Busboy = require('busboy');
  4.  
  5. function processUpload(req, res) {
  6.     var busboy = new Busboy({headers: req.headers});
  7.     busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
  8.         file.on('data', function(data) {
  9.             console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
  10.         });
  11.         file.on('end', function() {
  12.             console.log('File [' + fieldname + '] Finished');
  13.         });
  14.     });
  15.     busboy.on('field', function(fieldName, fieldValue, fieldNameTruncated, fieldValueTruncated) {
  16.         console.log('Field ', fieldName, 'with value', fieldValue);
  17.     });
  18.     busboy.on('finish', function() {
  19.         console.log('Done parsing form!');
  20.         res.writeHead(303, { Connection: 'close', Location: '/' });
  21.         res.end();
  22.     });
  23.     req.pipe(busboy);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement