0

I am using the Knox S3 module, but when I eventually get the file, the resulting file is corrupt. Am I using Knox incorrectly?

        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.
            });
        });
ben75
  • 29,217
  • 10
  • 88
  • 134
Benny
  • 3,899
  • 8
  • 46
  • 81

1 Answers1

1

Try using the 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(); });
});

and make sure to take a look at https://github.com/aws/aws-sdk-js

Chris
  • 4,204
  • 1
  • 25
  • 30