Last active
August 29, 2015 14:15
-
-
Save secretfader/54a0d749ef98d9a38607 to your computer and use it in GitHub Desktop.
koa multipart
This file contains 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
router.post('/', multipart, function *() { | |
if (this.state.files && this.state.files.media) { | |
this.state.files.media.pipe(fs.createWriteStream(/* output */)); | |
// stream error handling omitted | |
} | |
}); |
This file contains 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
module.exports = function *(next) { | |
var parts = parse(this, { autoFields: true }) | |
, part; | |
this.state.files = {}; | |
while (part = yield parts) { | |
this.state.files[part.fieldname] = part; | |
part.resume(); | |
} | |
this.body = this.body || parts.field || {}; | |
yield next; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment