2

I am Currently saving the image into S3 Bucket using Skipper S3 npm module through Sails JS.

My Code for saving into s3 bucket using skipper is as follows:

req.file('imageName').upload({
        saveAs: 'FileName.png',
        adapter: require('skipper-s3'),
        key: 'key',
        secret: 'secret',
        bucket: 'bucketName'
    }, function whenDone(err, uploadedFiles) {
        if (err)
            //error handling
        else
            // return back the Image URl into S3.
    });

Currently I am following the methodology given in this link.This Methodology is not efficient and varies with the image size.

My Requirement is to resize the image(.png.jpg,.tif,.gif) into 3 different sizes (80*80,100*120 and 130*270). I want to save my initial image and 3 resized image into S3 Bucket simultaneously. But I am unable to extract the buffer for the given image through req.file.

I have referred the following questions on Stack overflow but I was unable to get my answer from them.

  1. Skipper in SailsJS (beta) image resize before upload
  2. Uploading multiple files with Sails.js 0.10 and Skipper using Dropzone.js
  3. Sails.js File upload with Skipper to AWS S3

Can somebody help with this?

Community
  • 1
  • 1
shubhamagiwal92
  • 1,362
  • 4
  • 25
  • 47

1 Answers1

4

You can separate the image resizing process from your app to AWS Lambda. Once your image have been just uploaded into S3 bucket, AWS Lambda function will be triggered. AWS gives a simple walkthrough to resize image: Handling Amazon S3 Events Using the AWS CLI (Node.js).

Edward Samuel
  • 3,846
  • 1
  • 22
  • 39
  • Hi Edward, Can you suggest me some examples as to how to code in AWS Lambda using node JS and npm modules? – shubhamagiwal92 Sep 08 '15 at 04:36
  • Actually the link that I mentioned before already give you an example how to create AWS Lambda function in NodeJS to create an thumbnail of an image. – Edward Samuel Sep 08 '15 at 06:50
  • But, if you want AWS Lambda function development properly, you can use Grunt to do that. See in this [article](https://aws.amazon.com/blogs/compute/continuous-integration-deployment-for-aws-lambda-functions-with-jenkins-and-grunt-part-1/). – Edward Samuel Sep 08 '15 at 06:52
  • Will this not increase AWS billing? – Rune Jeppesen Sep 06 '16 at 15:53
  • Beside S3 storage billing, it might charge you for AWS Lambda usage if your usage is more than free-tier limit (https://aws.amazon.com/free/#AWS_Lambda). – Edward Samuel Sep 07 '16 at 02:04
  • I created a project which does exactly what the answer suggests (https://github.com/adieuadieu/serverless-sharp-image). You can configure any number of image outputs. The project aims to be easy to setup so you can skip reading through the AWS documentation. – Marco Lüthy Feb 13 '17 at 04:59