Skip to content

How to use GetObjectCommand

Jun Yuan edited this page May 19, 2024 · 2 revisions
import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
// Create an S3 client service object
const imageUUID = req.query.uuid;

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("base64")));
    });

const s3Client = new S3Client({
    region: process.env.BUCKET_REGION,
    credentials: {
        accessKeyId: process.env.ACCESS_KEY_ID,
        secretAccessKey: process.env.SECRET_ACCESS_KEY
    }
});

//Set the parameters
const params = {
    Bucket: //Bucket Name,
    Key: //Object Key
};

//Command to get the object
const command = new GetObjectCommand(params);

var data = await s3Client.send(command);

Clone this wiki locally