I'm trying to upload an image to S3 with the Node AWS-SDK.
First I encode an image to BASE64 and then make a Buffer with Buffer.from. I then send the request to S3 with S3.upload or S3.PutObject. It is working however it is extremely slow...
An image of size 150kb uploaded to a S3 Bucket takes around 30 - 60 seconds! I have tried setting different regions, but with no effect.
The code is like follows:
let buf = Buffer.from(
base64.replace(/^data:image\/\w+;base64,/, ""),
"base64"
);
const uploadParams = {
Bucket: "BUCKETNAME",
Body: BUFFERFILE,
Key: fileName,
ContentEncoding: "base64",
ContentType: "image/jpeg",
};
s3.upload(uploadParams, function (err, data) {
if (err) {
console.log(err);
console.log("Error uploading data: ", data);
} else {
console.log("succesfully uploaded the image!");
}
});
Any help is appreciated! I am stuck at this point for a long time now...