Unable to read file bytes accurately for jpeg/jpg s3 objects

0

I am using node express js and using aws-sdk v3. I am able to properly read the filebytes for png and pdf files using the below code. But whenever I try to get the file bytes for jpg or jpeg s3 files, it doesnt return the SOI marker. Is there a way to be able to read the jpg/jpeg file bytes accurately?

const getObjectCommand = new GetObjectCommand({
Bucket: bucket,
Key: object.Key,
});
const getObjectResponse = await s3Client.send(getObjectCommand);
const fileBytes = await new Promise((resolve, reject) => {
const chunks = [];
getObjectResponse.Body.on("data", (chunk) => chunks.push(chunk));
getObjectResponse.Body.on("end", () => resolve(Buffer.concat(chunks)));
getObjectResponse.Body.on("error", (error) => reject(error));
});
asked 8 months ago163 views
1 Answer
1
profile picture
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions