Error: read ECONNRESET ExpressJS and Amazon S3

Im using the Knox S3 plugin in an ExpressJS web application to display an image uploaded to Amazon S3. When displaying an image, I sometimes get an error below. I have no idea about the error. What caused the error?

events.js:72 throw er; // Unhandled 'error' event ^ Error: read ECONNRESET at errnoException (net.js:884:11) at TCP.onread (net.js:539:19) 

Here's how I make an image with Amazon S3:

 var data = ''; client.get(url).on('response', function(s3res) { s3res.setEncoding('binary'); s3res.on('data', function(chunk){ data += chunk; }); s3res.on('end', function() { res.contentType('image/jpg'); res.write(data, encoding='binary'); res.end(); }); }).end(); 
+4
source share
1 answer

Since a sink event can occur for a stream, it is possible that you are writing faster than another stream is capable of reading. You should use a channel that processes this for you:

 s3res.pipe(response); 

http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options

This is from the nodejs documentation: This method pulls all the data from the read stream and writes it to the designated destination, automatically controlling the stream so that the receiver is not overloaded with a fast read stream.

0
source

Source: https://habr.com/ru/post/1500747/


All Articles