Created
May 26, 2022 01:31
-
-
Save mmmulani/8b3adb62713e9c2d49f3ffb6faa07d89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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