node.js套接字与aws-sdk挂起

时间:2016-01-07 03:26:20

标签: node.js amazon-s3 aws-sdk

我在AWS S3中有超过50个csv文件(每个文件大约4MB)。 我想读取所有文件并推送数组,但我有" socket挂断错误"在程序中。 (当少于20个文件时,不会出现错误。)

如何解决此错误?

错误 -

{ [NetworkingError: socket hang up]
  message: 'socket hang up',
  code: 'NetworkingError',
  region: 'ap-northeast-1',
  hostname: 'hoge.s3-ap-northeast-1.amazonaws.com',
  retryable: true,
  time: Thu Jan 07 2016 11:09:46 GMT+0900 (JST) }

/home/bitnami/node_modules/aws-sdk/lib/sequential_executor.js:229
        throw err;
              ^
TypeError: Cannot read property 'Body' of null
    at Response.<anonymous> (/home/bitnami/app_piyo.js:18:34)
    at Request.<anonymous> (/home/bitnami/node_modules/aws-sdk/lib/request.js:345:18)
    at Request.callListeners (/home/bitnami/node_modules/aws-sdk/lib/sequential_executor.js:104:18)
    at Request.emit (/home/bitnami/node_modules/aws-sdk/lib/sequential_executor.js:79:10)
    at Request.emit (/home/bitnami/node_modules/aws-sdk/lib/request.js:599:14)
    at Request.transition (/home/bitnami/node_modules/aws-sdk/lib/request.js:19:12)
    at AcceptorStateMachine.runTo (/home/bitnami/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/bitnami/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/bitnami/node_modules/aws-sdk/lib/request.js:25:9)
    at Request.<anonymous> (/home/bitnami/node_modules/aws-sdk/lib/request.js:601:12)

[每个版本] node.js v0.10.26 aws-sdk@2.0.17 csv@0.4.0

计划 -

var csv = require('csv'),
    aws = require('aws-sdk');
aws.config.region = 'ap-northeast-1';

var s3bucket = new aws.S3({ params: { Bucket: 'hoge' } });
s3bucket.listObjects({
  Bucket: 'hoge',
  Prefix: 'piyo'
}, function (err, listObjects) {
  if (err) { console.error(err) }
  listObjects.Contents.forEach(function (content) {
    if (content.Size > 0) {
      var key = content.Key;
      s3bucket.getObject({ Key: key }, function (err, data) {
        console.log(key);
        var newData = [];
        if (err) { console.error(err) }
        csv.parse(new Buffer(data.Body, 'base64').toString('utf8'), function (err, rawData) {
          var header = rawData[0], newCsvFileName;
          if (err) { console.error(err) }
          rawData.forEach(function (line, lineIndex) {
            line.forEach(function (col, colIndex) {
              if (colIndex != 0) {
                var time = line[0];
                newData.push([time, key, header[colIndex], col]);
              }
            });
          });
        });
      });
    }
  });
});

谢谢。

0 个答案:

没有答案