Skip to content

Commit

Permalink
Merge pull request #3876 from cpyle0819/corepyle/#3597/s3-getobject-u…
Browse files Browse the repository at this point in the history
…pdate

Update GetObject example to use new transform util.
  • Loading branch information
scmacdon authored Oct 28, 2022
2 parents 9f723cf + 277b11e commit 96db7f3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
2 changes: 1 addition & 1 deletion javascriptv3/example_code/s3/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache 2.0",
"transform": {},
"dependencies": {
"@aws-sdk/client-s3": "^3.32.0",
"@aws-sdk/client-s3": "^3.196.0",
"@aws-sdk/node-http-handler": "^3.32.0"
},
"scripts": {
Expand Down
17 changes: 3 additions & 14 deletions javascriptv3/example_code/s3/src/s3_getobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Inputs (replace in code):
- KEY
Running the code:
nodes3_getobject.js
node s3_getobject.js
[Outputs | Returns]:
Returns the object} from the Amazon S3 bucket.
Expand All @@ -30,26 +30,15 @@ export const bucketParams = {

export const run = async () => {
try {
// Create a helper function to convert a ReadableStream to a string.
const streamToString = (stream) =>
new Promise((resolve, reject) => {
const chunks = [];
stream.on("data", (chunk) => chunks.push(chunk));
stream.on("error", reject);
stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
});

// Get the object} from the Amazon S3 bucket. It is returned as a ReadableStream.
const data = await s3Client.send(new GetObjectCommand(bucketParams));
return data; // For unit tests.
// Convert the ReadableStream to a string.
const bodyContents = await streamToString(data.Body);
console.log(bodyContents);
return bodyContents;
return await data.Body.transformToString();
} catch (err) {
console.log("Error", err);
}
};

run();
// snippet-end:[s3.JavaScript.buckets.getobjectV3]
// For unit testing only.
Expand Down
15 changes: 0 additions & 15 deletions javascriptv3/example_code/s3/tests/s3_getobject.test.js

This file was deleted.

0 comments on commit 96db7f3

Please sign in to comment.