Skip to content

Computing checksum using S3.getObject() #4149

Answered by colesiegel
colesiegel asked this question in Q&A
Discussion options

You must be logged in to vote

I eventually got the solution here by using a read stream instead of the promise version of getObject:

  return new Promise((resolve, reject) => {
    const hash = createHash('sha256');
    const stream = S3.getObject({ Bucket: bucketName, Key: fileName }).createReadStream();

    stream.on('data', (d) => hash.update(d));
    stream.on('end', () => {
      const digest = hash.digest('hex');
      logger.debug(`SHA256: [${digest}]`);
      resolve(digest);
    });
    stream.on('error', reject);
  });

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by colesiegel
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant