Closed violinxliu closed 7 years ago
When you do a npm list
, do you have multiple entries for formidable
?
No.maybe you should have a try or can you show us a demo.
I have some ideas for why it does not work. I would give a try, however, I do not have koa-formidable
in use currently and I am not sure if I find some time to setup a working example in next couple of days.
Anyway, Thank you for your reply. I will try continue to fix this, even I have finish my problem by any other solution. By the way, do you have Gitter account, maybe we can talk more convenient with this IM.
I can be found on matrix.org/riot.im (as rkusa), which has a Gitter bridge, but I have never used it.
I think the issue could be the following lines https://github.com/rkusa/koa-formidable/blob/master/index.js#L21-L23
var form = opts instanceof formidable.IncomingForm
? opts
: new formidable.IncomingForm(opts)
Because, if the require('formidable')
of koa-formidable
receives a different IncomfingForm
then your require('formidable')
does, then koa-formidable
creates a new instance instead of using yours (because instanceof
fails). If this is the case, changing the instanceof
statement into something like typeof opts.parse === 'function'
, may fix the issue.
ok, I am busy now. later I will try. well, Thank you and have a nice day.
so excited to tell you that your idea is right.
/ fix this issue, just like this. I had proved this is right on my project. */ var form = typeof opts.parse === 'function' ? opts : new formidable.IncomingForm(opts);
var form = opts && opts.parse && typeof opts.parse === 'function'
? opts
: new formidable.IncomingForm(opts)
The code like this will be more better.
Thanks for checking back!
May I ask you a favor? Could you check if the following works, too:
var form = (opts && typeof opts === 'function' && opts.constructor.name === 'IncomingForm')
? opts
: new formidable.IncomingForm(opts)
This would be a more correct solution. If it works, I would like to integrate this change and publish a new version
your code has something wrong. because opts is an object. well, I think the code like this is fine.
var form = (opts && typeof opts === 'object' && typeof opts.parse === 'function' && opts.constructor.name === 'IncomingForm')
? opts
: new formidable.IncomingForm(opts)
Ah right.
var form = (typeof opts === 'object' && opts.constructor.name === 'IncomingForm')
? opts
: new formidable.IncomingForm(opts)
should do the trick then. I'll update the library. Thanks for testing
Great! when are you going to publish the new version? er, Can I make a suggestion? I think you should update the document about how to use the events of formidable on README.md. because it will be more detailed for developer to use your lib.
I've release 1.1.0
and added an example to the README. Next step would probably to release a version compatible with the most recent Koa using async/await
... but I need to setup either tests or an example application first ...
Great! I had saw it. In order to compatible with Koa2, you have to do so. Everything takes time, so there's no hurry, just follow the plan you make step by step.
the 'fileBegin', 'aborted', 'end', all of these events do not work. How to fix it?