从Amazon S3直接将文件stream式传输到客户端(Node.js)
我正在使用sails.js,并试图将文件从Amazon S3服务器直接传输到客户端。
要连接到S3,我使用s3模块: https : client.downloadBuffer(s3Params)
此模块提供像client.downloadFile(params)
和client.downloadBuffer(s3Params)
。
我目前的代码如下所示:
var view = client.downloadBuffer(params); view.on('error', function(err) { cb({success: 0, message: 'Could not open file.'}, null); }); view.on('end', function(buffer) { cb(null, buffer); });
我用一个控制器捕获这个缓冲区:
User.showImage( params , function (err, buffer){ // this is where I can get the buffer });
是否有可能将此数据作为图像文件进行stream式传输(当然,使用buffer.pipe(res)
不起作用)。 但是有没有类似于完全避免将文件保存到服务器磁盘?
另一个选项client.downloadFile(params)
需要一个本地path(即在我们的例子中是一个服务器path)
GitHub的问题包含这个问题的“官方”答案: https : //github.com/andrewrk/node-s3-client/issues/53
- AWS Transfer Acceleration使用JavaScript SDK的预签名URL
- 我可以从S3对象stream中获取Content-Type而无需对headObject进行显式调用吗?
- 如何在客户端将可查看file upload到Amazon S3?
- nodejs – 使用fs.createReadStream,requestjs,streaming和AWS S3 presigned url上传会引发错误
- 无法使用node.js将Blobfile upload到S3
- 用NodeJS检索远程文件进行存储?
- 如何在KeystoneJS上传S3文件
- Amazon S3 POST API以及使用NodeJS签署策略
- 在Mongo GridFS或Amazon S3中存储图像的速度更快?