且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从nodejs请求到s3的流响应

更新时间:2023-09-26 16:06:10

如果要手动侦听响应流,则要使用response对象:

You want to use the response object if you're manually listening for the response stream:

var req = require('request');
var s3 = new AWS.S3({params: {Bucket: myBucket, Key: s3Key}});
var imageStream = req.get(url)
    .on('response', function (response) {
      if (200 == response.statusCode) {
        s3.upload({Body: response, ACL: "public-read", CacheControl: 5184000}, function (err, data) {  //2 months
          console.log(err,data);
        });
      }
    });
});