Skip to content

getObject returns corrupted file? #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
radekg opened this issue Dec 31, 2012 · 5 comments
Closed

getObject returns corrupted file? #19

radekg opened this issue Dec 31, 2012 · 5 comments

Comments

@radekg
Copy link

radekg commented Dec 31, 2012

I trying different variants of this:
http://stackoverflow.com/questions/14020065/problems-downloading-a-binary-file-with-aws-sdk

I also seem to be getting a corrupted file, few KBs off. Do you have a working example?

@radekg
Copy link
Author

radekg commented Jan 3, 2013

Answering my own question:

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();

@radekg radekg closed this as completed Jan 3, 2013
@radekg
Copy link
Author

radekg commented Jan 8, 2013

I've installed this package from master and this example has stopped working.

TypeError: Object #<Request> has no method 'data'

@radekg radekg reopened this Jan 8, 2013
@lsegal
Copy link
Contributor

lsegal commented Jan 9, 2013

We've made changes to the Request class API since 0.9.1.pre-2. The changes are currently only in master and have not yet been released, so there isn't much available documentation. This will change by the next release, but to quickly get you going, you can rewrite the above as:

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();

Note that we may be adding more streaming support before the next preview release, so the API might be simplified considerably to something like:

var out = fs.createWriteStream("/tmp/test.jpg", { flags: 'w', encoding: null, mode: 0666 });
s3.client.getObject({ Bucket: bucket, Key: key }).createReadStream().pipe(out);

I would suggest that you should run off of the npm package releases until the next preview is out unless you explicitly want to experiment with the current features that are in the works-- with the caveat that some documentation may not be in sync until we push out the next release.

@radekg
Copy link
Author

radekg commented Jan 9, 2013

Yes, yes, I've found it. The changes were implemented here: #22, thank you.

@lock
Copy link

lock bot commented Sep 30, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants