Skip to content

Instantly share code, notes, and snippets.

@wavded
Created November 6, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wavded/9355d1ef9181c4ddb1ee to your computer and use it in GitHub Desktop.
Save wavded/9355d1ef9181c4ddb1ee to your computer and use it in GitHub Desktop.
exports.bufferOrderFile = function (req) {
const d = exports.createDeferred()
var name
const data = []
// Capture errors but intentially resolve to undefined
const captureErAndRes = er => { log.err(er); d.resolve() }
try {
const busboy = new Busboy({
headers: req.headers,
limits: {
fields: 0, // No fields will be parsed
files: 1, // Any file after the first will be drained
fileSize: 1000000 // 1 MB upload limit
}
})
busboy.once('file', (field, rstream, filename) => {
name = filename
rstream.on('data', buffer => data.push(buffer))
rstream.once('error', captureErAndRes)
})
busboy.once('error', captureErAndRes)
busboy.once('finish', _ => d.resolve({ name, buffer: Buffer.concat(data) }))
req.pipe(busboy)
}
catch (er) { captureErAndRes(er) }
return d.promise
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment