Open xinshouke opened 8 years ago
you need await
a promise while busboy doesn't support yet
const convert = require('koa-convert'); app.use(convert(function (next) { // the body isn't multipart, so busboy can't parse it if (!this.request.is('multipart/')) return yield next;
var parts = parse(this,{autoFields:true});
var part;
var fields={};
while (part = yield parts) {
if (part.length) {
// arrays are busboy fields
fields[part[0]]=part[1];
console.log('key: ' + part[0])
console.log('value: ' + part[1])
} else {
// otherwise, it's a stream
}
}
console.log('and we are done parsing the form!')
}));
I plan to test a file upload using multipart/form-data in koa2, the below was my code:
the below was the dump of ctx in log:
but I get the below error as below,my question is :how to get the uploading file name and the content of uploading file ? [TypeError: part.pipe is not a function]