Skip to content

Instantly share code, notes, and snippets.

@mmmulani
Created May 26, 2022 01:31
Show Gist options
  • Save mmmulani/8b3adb62713e9c2d49f3ffb6faa07d89 to your computer and use it in GitHub Desktop.
Save mmmulani/8b3adb62713e9c2d49f3ffb6faa07d89 to your computer and use it in GitHub Desktop.
(req, res, next) => {
let parsing = false;
const RE_BOUNDARY = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i;
if (req.headers['content-type']) {
const regexResult = RE_BOUNDARY.exec(req.headers['content-type']);
if (regexResult) {
parsing = true;
const boundary = regexResult[1] || regexResult[2];
const d = new Dicer({ boundary });
d.on('part', p => {
p.on('error', (e) => {
console.log('got part error', e);
});
});
d.on('finish', () => {
next();
});
req.pipe(d);
}
}
if (!parsing) {
next();
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment