koajs / joi-router

Configurable, input and output validated routing for koa
MIT License
450 stars 96 forks source link

await-busboy not working properly #44

Closed thakkaryash94 closed 5 years ago

thakkaryash94 commented 7 years ago

Multipart request not returning proper ctx.request.parts object. returns FileStream object without path key which contains file temp path and form-data key-values are also not returning. I tried async-busboy. works fine with the same request. It returns {files, fields}, if you say, I can take a chance to migrate from await-busboy to async-busboy.

aheckmann commented 7 years ago

Sounds like this is working as intended, it should be returning streams. Up to the app how to handle it.

thakkaryash94 commented 7 years ago

I think it suppose to return fields also. Is while loop is compulsory,

while ((part = await ctx.request.parts)) {
  part.resume()
}

only await ctx.request.parts isn't working, I have to loop it.

aheckmann commented 7 years ago

Please post a failing test I can run so I can help debug when I get a chance

stephensong commented 7 years ago

The problem may be related the one I was having in trying to access non-stream data parts - which in :autofields mode should appear on ctx.request.parts.field (object) and .fields (array). The problem I encountered was that these attributes are incrementally added as the while loop proceeds, and can really only be sensibly accessed after it's completion. When I turned off :autofields mode, I was able to process the non-stream parts sequentially as the loop executed, which for me is far preferable. Unfortunately, the current code mandates that autofields be true, and provides no facility to override it. I could try put a pull request together to allow it to be overridden. Should I?

aheckmann commented 5 years ago

You can disable autoFields by setting validate.multipartOptions.autoFields: false. I've updated the docs