I have a file on an S3 bucket - I am able to query the bucket, so I know the credentials and parameters for the bucket are correct. I have the following code (from the AWS examples) :
const run = async () => {
try {
// Get the object} from the Amazon S3 bucket. It is returned as a ReadableStream.
const data = await s3Client.send(new GetObjectCommand(bucketParamsGet));
// Convert the ReadableStream to a string.
const fileInfo = await data.Body?.transformToString()
// return await data.Body.transformToWebStream()
// console.log(data)
const filename = data.Body.req.path
console.log('>>> ',filename)
await fs.writeFile('./testfile', fileInfo, (err) => {
if (err)
console.log(err)
else {
console.log('tada')
}
});
return fileInfo
} catch (err) {
console.log("Error", err);
}
};
run();
I added the writeFile to see if I could just simply write the file to disc, what I got was a file much larger than what was uploaded. I think my issue is around the fact that the file is being saved as a string - however, I can't see how to save this as a jpg (or whatever the original file was)