Skip to content

co-busboy was unable to parse ctx using multipart/form-data in koa2  #33

@xinshouke

Description

@xinshouke

I plan to test a file upload using multipart/form-data in koa2, the below was my code:

var parts = parse(ctx.request);
// or var parts = parse(ctx);
var part;
while (part = await parts) {
var stream = 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);
}

the below was the dump of ctx in log:

ctx===> { request:
   { method: 'POST',
     url: '/upload',
     header:
      { host: '127.0.0.1:3000',
        connection: 'keep-alive',
        'content-length': '2316',
        'cache-control': 'max-age=0',
        accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        origin: 'http://127.0.0.1:3000',
        'upgrade-insecure-requests': '1',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36 Core/1.47.277.400 QQBrowser/9.4.7658.400',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryJl7OKIVqHwYSA5fz',
        referer: 'http://127.0.0.1:3000/',
        'accept-encoding': 'gzip, deflate',
        'accept-language': 'zh-CN,zh;q=0.8' } },
  response: { status: 404, message: 'Not Found', header: {} }

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions