Permalink
Browse files

feat: add busboy dependency

  • Loading branch information...
jimlambie committed Dec 13, 2016
1 parent 239ce13 commit 3eda9fe4df636955f446f4546190e1d08dc3f288
Showing with 39 additions and 0 deletions.
  1. +38 −0 dadi/lib/controller/index.js
  2. +1 −0 package.json
@@ -13,6 +13,7 @@ implements methods corresponding to the HTTP methods it needs to support
*/
var _ = require('underscore')
var Busboy = require('busboy')
var path = require('path')
var url = require('url')

@@ -217,6 +218,43 @@ Controller.prototype.post = function (req, res, next) {
// for clearing the cache
pathname = pathname.replace('/' + req.params.id, '')

var busboy = new Busboy({ headers: req.headers })
this.data = []
this.fileName = ''

// Listen for event when Busboy finds a file to stream
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
this.fileName = filename
this.mimetype = mimetype

file.on('data', (chunk) => {
this.data.push(chunk)
})

file.on('end', () => {
// console.log('Finished with ' + fieldname)
})
})

// Listen for event when Busboy finds a non-file field
busboy.on('field', (fieldname, val) => {
// Do something with non-file field.
})

// Listen for event when Busboy is finished parsing the form
busboy.on('finish', () => {
var data = Buffer.concat(this.data)
console.log(data)

console.log(this)
// return writeFile(req, this.fileName, this.mimetype, data). then((result) => {
// help.sendBackJSON(201, result, res)
// })
})

// Pipe the HTTP Request into Busboy
req.pipe(busboy)

// flush cache for POST requests
help.clearCache(pathname, function (err) {
if (err) return next(err)
@@ -16,6 +16,7 @@
"async": "^1.4.2",
"body-parser": "~1.6.5",
"bunyan": "^1.5.1",
"busboy": "^0.2.13",
"chokidar": "^1.5.2",
"cli-prompt": "^0.6.0",
"colors": "^1.1.2",

0 comments on commit 3eda9fe

Please sign in to comment.