Node Busboy abort upload

前端 未结 5 818
情书的邮戳
情书的邮戳 2021-01-04 10:37

I\'m using busboy, writing my uploaded file to a buffer and performing some validation on it (width, height and filesize). I can\'t for the life of me figure out how to abo

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 11:04

    The answer is simple one.

    // do the required validation like size check etc.
    if( size > 500000) 
    {
        self.req.unpipe();
        return;
    }
    

    The context is this. I see in busboy code that busboy is implemented as WritableStream and underneath uses Dicer module for parsing which is also implemented as WritableStream. Flow is like this:

    req stream ==> busboy ==> dicer ==> dicer raises events ==> busboy raises events on file ==> these events are consumed in your code.

    To stop this whole flow of code - the above unpipe should do.

提交回复
热议问题