createReadStream()
aws-sdkを使用してノードで S3 からコンテンツをストリーミングしています。etag のサポートを追加したいと考えています。クライアントから「If-None-Match」ヘッダーを追加すると、s3 は NotModified をエラーとしてスローし、処理できないようです。
retrieveFile = function(req, res) {
var s3 = new AWS.S3();
var params = {
Bucket: bucket,
key: key
};
if (req.get('If-None-Match')) {
params.IfNoneMatch = req.get('If-None-Match');
}
return s3.getObject(params).on('httpHeaders', function(statusCode, headers) {
if (headers.etag) {
res.set('etag', headers.etag);
}
if (headers['content-length']) {
return res.set('content-length', headers['content-length']);
}
}).createReadStream().pipe(res);
};
ストリームでイベントをリッスンし、getObject から返されたリクエストでコールバックを使用しようとしました。その方法でエラーメッセージを取得できますが、aws-sdk の他の何かがプロセスを強制終了しているようです。
/Projects/my-app/node_modules/aws-sdk/lib/request.js:31
throw err;
^
NotModified: null
at Request.extractError (/Projects/my-app/node_modules/aws-sdk/lib/services/s3.js:519:35)
at Request.callListeners (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/Projects/my-app/node_modules/aws-sdk/lib/request.js:673:14)
at Request.transition (/Projects/my-app/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Projects/my-app/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Projects/my-app/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Projects/my-app/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Projects/my-app/node_modules/aws-sdk/lib/request.js:675:12)
at Request.callListeners (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
at Request.emit (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/Projects/my-app/node_modules/aws-sdk/lib/request.js:673:14)
at Request.transition (/Projects/my-app/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Projects/my-app/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Projects/my-app/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Projects/my-app/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Projects/my-app/node_modules/aws-sdk/lib/request.js:675:12)
at Request.callListeners (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
at callNextListener (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
at IncomingMessage.onEnd (/Projects/my-app/node_modules/aws-sdk/lib/event_listeners.js:244:11)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)