Reputation: 331
I'm switching my server over from knox to the official aws-sdk, but I'm having some discrepancies with the end results.
In aws-sdk, I use getObject to get a file in this manner:
svc.client.getObject({Bucket:"someBucket",
Key:file,
ResponseContentEncoding:"application/octet-stream"},
function(err, data) {
if(!err)
{
var buff = new Buffer(data.Body, "binary");
var fd = fs.openSync(file + ".aws", "w");
fs.writeSync(fd, buff, 0, buff.length,0);
}
});
I'm getting a file which appears to be a few bytes off, but when I compare it in a hex editor like BeyondCompare, a large number of bytes are off being replaced with 'FD'. Any insight on this?
Upvotes: 2
Views: 2708
Reputation:
Got it:
var writePos = 0;
var stream = fs.createWriteStream("/tmp/test.jpg", { flags: 'w', encoding: null, mode: 0666 });
s3.client.getObject({ Bucket: bucket, Key: key }).data(function(data) {
stream.write(data.data);
}).done(function() {
stream.end();
}).send();
Edit 9th of Jan 2012: There was an update to the library, if you're using latest from github:
var stream = fs.createWriteStream("/tmp/test.jpg", { flags: 'w', encoding: null, mode: 0666 });
s3.client.getObject({ Bucket: bucket, Key: key }).on('httpData', function(chunk) {
stream.write(chunk);
}).on('complete', function() {
stream.end();
}).send();
This was introduced in the following pull request: https://github.com/aws/aws-sdk-js/pull/22
Upvotes: 2