【问题标题】:How to consume response from Knox module?如何使用 Knox 模块的响应?
【发布时间】:2013-01-13 21:46:25
【问题描述】:

我正在使用 Knox S3 模块,但是当我最终获得文件时,生成的文件已损坏。我是否错误地使用了 Knox?

        var data;
        client.getFile(path, function(err, file) {
            file.on('data', function(chunk) { data += chunk; });
            file.on('end', function() {
                //Here I end up sending the response with new Buffer(data), but that produces a bad file.
            });
        });

【问题讨论】:

    标签: node.js amazon-web-services knox-amazon-s3-client


    【解决方案1】:

    尝试使用 writeStream:

    var fs = require('fs');
    var file = fs.createWriteStream(path);
    client.getFile(path, function(err, stream) {
        stream.on('data', function(chunk) { file.write(chunk); });
        stream.on('end', function(chunk) { file.end(); });
    });
    

    请务必查看https://github.com/aws/aws-sdk-js

    【讨论】:

    • 非常感谢您透露亚马逊自己的 SDK。不知道我是怎么错过的!
    猜你喜欢
    • 2020-06-20
    • 2012-12-18
    • 2021-09-24
    • 2017-08-04
    • 1970-01-01
    • 2016-03-13
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多