如何将已下载并通过节点解压缩的文件上传到S3

时间:2015-12-21 14:31:15

标签: node.js amazon-s3

我尝试过以下代码,但是收到错误:Error: EACCES, open 'out'

var out = fs.createWriteStream('out');
request(url).pipe(zlib.createGunzip()).pipe(out);
var s3obj = new aws.S3({ params: { Bucket: 'mybucket', Key: 'mykey' } });
s3obj.upload({ Body: out }, function(err, data) {                       
    context.succeed("Completed");
});

1 个答案:

答案 0 :(得分:0)

node.js是异步的,所以你必须这样做:

var s3obj = new aws.S3({ params: { Bucket: 'mybucket', Key: 'mykey' } });
var out = fs.createWriteStream('out');
request(url).pipe(zlib.createGunzip()).pipe(out)
  .on('end', function() {
    var uploadStream = fs.createReadStream('out')
    s3obj.upload({ Body: uploadStream }, function(err, data) {                       
      context.succeed("Completed");
    });