Amazon Web Services · sdk · fg-0180

S3 GetObject Body.toString() returns [object Object] or a stream instead of the file contents in AWS SDK v3

If you see response.Body.toString() prints [object Object] or IncomingMessage, the cause and the fix for Amazon Web Services are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
response.Body.toString() prints [object Object] or IncomingMessageTypeScript types Body as a union of Readable, ReadableStream and BlobJSON.parse fails on the object you just downloaded
Cause
In SDK v3 the Body is a runtime stream, not a Buffer as in v2. Later v3 releases attach helper methods to the stream that read it for you.
Fix
Await Body.transformToString() or transformToByteArray(). Read it once, because the stream is consumed by the first read.
Apply
const res = await s3.send(new GetObjectCommand({ Bucket, Key })); const text = await res.Body.transformToString(); const data = JSON.parse(text);
Affected
AWS SDK for JavaScript v3, @aws-sdk/client-s3 all versions; transformToString exists in releases from late 2022 onward
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun