i try to uplaoding file s3 resize lambda but icant save the file :-(
const AWS = require('aws-sdk');
const Jimp = require('jimp");
const resizeImageFromURL = async (imageUrl: string) => {
const _image = await Jimp.read(imageUrl);
const _newWidth; // TODO Add it yourself...
const _newHeight; // TODO Add it yourself...
const _operatedImage = _image.resize(_newWidth, _newHeight);
const _operatedImageBuffer = await _operatedImage.getBufferAsync(Jimp.MIME_PNG);
AWS.config.update({
accessKeyId: "SECRET",
secretAccessKey: "SECRET",
});
const s3 = new AWS.S3({
region: "us-east-1"
});
const s3UploadConfig: AWS.S3.Types.PutObjectRequest = {
ACL: "public-read", // OR maybe "bucket-owner-full-control"
Body: _operatedImageBuffer,
Bucket: "my-fun-bucket",
ContentType: "image/jpeg",
Key: "resized-images/output.jpg",
};
return s3.putObject(s3UploadConfig).promise();
// Should upload to https://s3.us-east-1.amazonaws.com/my-fun-bucket/resized-images/output.jpg
};
This should work..
Most helpful comment