Skip to content

Instantly share code, notes, and snippets.

@wavded wavded/sample.js
Created Nov 6, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.