4.2.0 • Published 4 years ago

multer-imager v4.2.0

Weekly downloads
71
License
MIT
Repository
github
Last release
4 years ago

multer-imager Build Status Codacy Badge Known Vulnerabilities

Imager multer storage engine permit to resize and upload an image to AWS S3.

This project is mostly an integration piece for existing code samples from Multer's storage engine documentation. And was inspired from multer-s3 and gm

Requirements

Debian/Ubuntu

apt-get install graphicsmagick

MacOS X

brew install graphicsmagick

Install

npm install multer-imager --save

Tests

Tested with s3rver instead of your actual s3 credentials. Doesn't require a real account or changing of hosts files. Includes integration tests ensuring that it should work with express + multer.

npm test

Usage

var express = require('express');
var app = express();
var multer = require('multer');
var imager = require('multer-imager');

var upload = multer({
  storage: imager({
    dirname: 'avatars',
    bucket: 'bucket-name',
    accessKeyId: 'aws-key-id',
    secretAccessKey: 'aws-key',
    region: 'us-east-1',
    filename: function (req, file, cb) {  // [Optional]: define filename (default: random)
      cb(null, Date.now())                // i.e. with a timestamp
    },                                    //
    gm: {                                 // [Optional]: define graphicsmagick options
      width: 200,                         // doc: http://aheckmann.github.io/gm/docs.html#resize
      height: 200,
      options: '!',
      format: 'png'                       // Default: jpg
      crop: {
        width: 200,
        height: 200,
        x: 0,
        y: 0
      }
    },
    s3 : {                                // [Optional]: define s3 options
      Metadata: {                         // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
        'customkey': 'data'               // "x-amz-meta-customkey","value":"data"
      }
    }
  })
});

// Cf.: https://github.com/expressjs/multer/blob/master/README.md
app.post('/upload', upload.array('file', 1), function(req, res, next){ 
  console.log(req.files); // Print upload details
  res.send('Successfully uploaded!');
});
4.2.0

4 years ago

4.1.0

4 years ago

4.0.0

5 years ago

3.3.3

5 years ago

3.3.2

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.0

6 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago