javascript - How to detect client closing connection during piping stream over http in node? -
i stream data server client in expressjs (nodejs) application.
i this;
// let contenttype , filename correctly defined in context function(req,res){ res.setheader('content-type',contenttype); res.setheader('content-disposition','attachment; filename='+filename); require('fs').createreadstream('/path/file').pipe(res); }
i want know when client fails download file, don't how proceed.
listen close
event on response object. emitted when connection client closed prematurely refreshing page or closing tab.
require('fs').createreadstream('/path/file').pipe(res).on('close',function(){ //do stuff closed connection })
Comments
Post a Comment