Jimp: how to upload file lambda function to s3 please help me

Created on 9 May 2019  路  2Comments  路  Source: oliver-moran/jimp

i try to uplaoding file s3 resize lambda but icant save the file :-(

Most helpful comment

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
};

All 2 comments

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..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SamuelZhaoY picture SamuelZhaoY  路  3Comments

DylanPiercey picture DylanPiercey  路  4Comments

sesirimarco picture sesirimarco  路  3Comments

dtrofimov picture dtrofimov  路  5Comments

slidenerd picture slidenerd  路  4Comments