How to cancel user upload in Formidable (Node.js)?

后端 未结 8 1090
[愿得一人]
[愿得一人] 2021-02-07 22:14

I have been working on this problem for two days now, and I am stuck. I am using Node.js with Express, and I am trying to implement an upload form. Basically, I want the form to

8条回答
  •  再見小時候
    2021-02-07 23:07

    I tried with your solution, it seemed it didn't work on my machine. Client couldn't get the response after I put this line this.emit('error'); within form.on section. It seemed my program was blocked. it meant you couldn't call your upload method twice. the second call wasn't executed since your program was blocked by this line: this.emit('Error'); already.

    upload:function(req, res) {
                var form = new multiparty.Form();
                form.on('error', function(message) {
                    res.send('Not Okay');
                });
                form.on('part', function(part) {
                    console.log('enter form on');
                    this.emit('Error');
                    res.send('Not Okay');
                });
                form.on('close', function(){
                    res.send('Not Okay');
                });
                form.parse(req);
        }
    

    The only solution I found was call part.resume(); within form.on section. it can consume your upload file on your server without touching your disk. but it will consume your network and server resources. Anyway, it's far better than program was blocked situation. That is why I'm keeping looking for another better way to resolve it.

提交回复
热议问题