2

私は NodeJS のストリームに非常に慣れていません - 基本的にそれらについては無知です - Amazon S3 の KnoxJS クライアントを取得して、HTTP GET からファイルをストリーミングしようとしています。

Knox github ページのサンプル コードは、これを示しています。


http.get('http://google.com/doodle.png', function(res){
  var headers = {
      'Content-Length': res.headers['content-length']
    , 'Content-Type': res.headers['content-type']
  };
  client.putStream(res, '/doodle.png', headers, function(err, res){
    // check `err`, then do `res.pipe(..)` or `res.resume()` or whatever.
  });
});

しかし、これは明らかに不完全です...実際には、S3のhttp.getandを開く以外には何もしません。putStream

ここからどこへ行けばいいの?HTTP GET から S3 のバケットにファイルをストリーミングできるように、誰かがこのコードを完成させるのを手伝ってくれますか?

4

1 に答える 1

2

Once you're inside this callback:

//check `err`, then do `res.pipe(..)` or `res.resume()` or whatever

The response from google has been streamed to S3 already (that's what knox's putStream does for you), and err, res are S3's response, so you don't have to anything else here other than check error and something like console.log("Upload done") if this is a command line snippet. Their docs here are saying if this entire snippet was within the context of an HTTP req/res interaction between say a browser and a node.js web app, then you could do decide you wanted to pipe the image back to the browser as well, you could do that (at least in theory). I think the docs are a bit confusing about that, but that's my interpretation.

于 2014-02-07T21:55:51.487 に答える