-
Notifications
You must be signed in to change notification settings - Fork 580
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
S3 GetObject returns a stream body #6707
Comments
The linked page states the return type of the body in S3 GetObject is a stream in the section "Example Syntax" and in the section "GetObjectCommand Output". Also take a look at https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/javascript_s3_code_examples.html#basics. As part of #6691, we will be creating additional documentation for streaming operations. |
There is nothing readable in there, I am not a beginner programmer and the usage example isn't a real code example... Just a bunch of convoluted text with no meaning. Every other Nodejs SDK out there shows you how to implement, but Amazon is way above that. ---------------------------------ACTUAL CODE EXAMPLE---------------------------------------------
} catch (error) {
|
Using the example from https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/javascript_s3_code_examples.html#basics, you do not need to concatenate into a buffer yourself. import {
GetObjectCommand,
S3Client,
} from "@aws-sdk/client-s3";
const response = await client.send(
new GetObjectCommand({
Bucket: bucketName,
Key: key,
}),
);
const str = await response.Body.transformToString();
console.log(str); // a string. Alternatively, a byte array // Uint8Array, which can be converted to Buffer.
const bytes = await response.Body.transformToByteArray(); |
Currently, the developer guide linked above contains more practical examples than the auto-generated API shape documentation you have seen. We plan to integrate this example into the API docs in a future update. |
Describe the issue
This documentation is absolutely deplorable, without chatGPT I would've been unable to use S3. Literally not one word about 'getObjectCommand' returning data in streams and you having to handle the chunks with a promise. All I wanted to do was to upload an image from a nodeJs server and then read it from S3. Of course, this simple task took me several hours because getting the body from an S3 file is apparently a herculean task
Links
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/command/GetObjectCommand/
The text was updated successfully, but these errors were encountered: