on('httpData', function(chunk, response) { ... })
Note
If you register a httpData callback, response.data will still contain serialized output for the
entire request. It will be your responsibility to remove the default 'httpData' listener if you do not
wish to have the extra parsing and memory overhead from the built-in handlers.
The httpData event is used to stream response data from the service packet-by-packet.This event is
mostly used for large responses, when it is inefficient (or impossible) to load the entire response into
memory.
Note that this event contains an extra chunk parameter containing the actual data passed on by the
server.
The always event triggers a callback in any final state of a request, i.e., both done and fail. Use this
callback to handle any request cleanup that must be executed regardless of the success state. Note that
if you do intend to use response data inside of this callback, you must check for the presence of
response.data or response.error before attempting to access either property. For example:
Multiple Callbacks and Chaining
You can register multiple callbacks on any request object.The callbacks can be registered for different
events, or all for the same event. In addition, you can chain callback registration, for example:
request.
on('success', function(response) {
console.log("Success!");
}).
on('error', function(response) {
console.log("Error!");
}).
on('complete', function() {
console.log("Always!");
}).
send();
The above example will print either "Success! Always!", or "Error! Always!", depending on whether the
request succeeded or not.
Version 0.9.1-pre.2 : Preview
13
AWS SDK for Node.js Getting Started Guide
on('httpData', function(chunk, response) {
... })