You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I plan to test a file upload using multipart/form-data in koa2, the below was my code:
varparts=parse(ctx.request);// or var parts = parse(ctx);varpart;while(part=awaitparts){varstream=fs.createWriteStream(path.join(os.tmpdir(),Math.random().toString()));console.log('part===>',part);part.pipe(stream);console.log('uploading %s -> %s',part.filename,stream.path);}
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]
The text was updated successfully, but these errors were encountered:
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]
The text was updated successfully, but these errors were encountered: