Giter Site home page Giter Site logo

alexandre-io / multer-imager Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 13.0 849 KB

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

License: MIT License

JavaScript 100.00%
multer multer-imager image s3 resize graphicsmagick gm amazon

multer-imager's Introduction

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!');
});

multer-imager's People

Contributors

alexandre-io avatar b0rgbart3 avatar dependabot[bot] avatar greenkeeper[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

multer-imager's Issues

An in-range update of gm is breaking the build 🚨

Version 1.23.1 of gm was just published.

Branch Build failing 🚨
Dependency gm
Current Version 1.23.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

gm is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 7 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of s3rver is breaking the build 🚨

The devDependency s3rver was updated from 2.2.6 to 2.2.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

s3rver is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v2.2.7

Fixes:

  • Exit with non-zero status with misconfigured data directory #325
  • Handle the case where the access-control-request-header is not provided #347

Tooling:

Commits

The new version differs by 40 commits.

  • 85d1d1d Increment version to v2.2.7
  • 2594675 chore(deps): update dependency aws-sdk to v2.369.0
  • 2ec958a Merge pull request #347 from justinmchase/fix/346-handle-empty-acrh
  • 80ad50c Merge pull request #325 from jamhall/error-exit-status
  • 39dbf72 chore(deps): update dependency aws-sdk to v2.368.0
  • 23b752a Refactor for clarity based on CR feedback
  • 03ae68c chore(deps): update dependency prettier to v1.15.3
  • f1fbe9c Fix prettier errors
  • 597f29e Handle the case where the access-control-request-header is not provided
  • 02389b9 chore(deps): update dependency aws-sdk to v2.362.0
  • 325e841 chore(deps): update dependency aws-sdk to v2.361.0
  • 4ece647 chore(deps): update dependency aws-sdk to v2.358.0
  • 98a0646 chore(deps): update dependency aws-sdk to v2.354.0
  • 7eb0f67 chore(deps): update dependency aws-sdk to v2.353.0
  • 7cc8527 chore(deps): update dependency eslint-config-prettier to v3.3.0

There are 40 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

How to use GM options

I'm still hoping / looking for for documentation or examples for using the Graphics Magick options.

The sample code works great--

    gm: {                             
      width: 200,                
      height: 200,
      options: '!',
      format: 'png'                      
    },

But I'd like to be able to use things like crop or scale, like this:

    gm: {                         
      crop: {
           x: 100, y:100, width:200, height:200
      },
      options: '!',
      format: 'png'                       // Default: jpg
    },

But I don't know how I should configure these options -- and I don't know if they are included or made accessible by multer-imager. So far they just seem to get ignored completely. Should they be structured in an object format like this? Is there somewhere this id documented? The main graphics magick documentation explains the CLI version, and the javascript -based version-- but doesn't cover how to structure these options.

Files uploading but at zero bytes size

const multerOptions = multer({
  storage: imager({
    accessKeyId: process.env.AWS_ACCESS,
    secretAccessKey: process.env.AWS_SECRET_KEY,
    bucket: process.env.AWS_BUCKET,
    region: process.env.AWSregion,
    /*acl: 'public-read',
    // Auto detect contet type
    contentType: multerS3.AUTO_CONTENT_TYPE, */
    dirname: 'images',
    filename: function(req, file, cb) {
      const extension = file.mimetype.split('/')[1]; // gets the extension
      const area = 'test_';
      const fileName = `${area}${uuid.v4()}.${extension}`;
      console.log('file name is ', fileName);
      cb(null, fileName);
    },
    gm: {
      pool: 5,
      format: 'png',
      scale: {
        width: 200,
        height: 200,
        type: 'contain',
      },
      crop: {
        width: 200,
        height: 200,
        x: 0,
        y: 0,
      },
      rotate: 'auto',
    },
   **// This part is not being executed.**
    fileFilter(req, file, next) {
      const isPhoto = file.mimetype.startsWith('image/');
      console.log(req.files);
      if (isPhoto) {
        next(null, true); // null for error means it worked and it is fine to continue to next()
        console.log(isPhoto);
      } else {
        next({ message: 'Fotos: Tipo de arquivo não suportado!' }, false); // with error
      }
    },
    s3: {
      Metadata: {
        ACL: 'public-read',
        customkey: 'data',
      },
    },
  }),
});

exports.upload = multer(multerOptions).array('photos', 5);

Files are going to S3 with the right name but at zero bytes, the commented part is not getting executed either. Ideas?

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of s3rver is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 2.2.2 of s3rver was just published.

Branch Build failing 🚨
Dependency s3rver
Current Version 2.2.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

s3rver is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v2.2.2

Fixes:

  • Correctly format XML date (#182)
  • Include correct IsTruncated value in listObjects response #187
  • Include bucket name in listObjects XML response (Regression) #186
  • Include missing size and MD5 in certain event types (Regression) #188

Tooling:

  • Use co-mocha for async tests (#177)
  • Update aws-sdk (#184)
Commits

The new version differs by 25 commits.

  • c51f5e8 Publish a 2.2.2 patch version
  • 3c0843d chore(deps): update dependency aws-sdk to v2.210.0
  • 2c663ca Merge pull request #188 from jamhall/fix-s3event
  • 535f717 fix(s3Event): Size and MD5 missing in certain event types
  • c28f8cc Merge pull request #187 from jamhall/fix-listobjects-istruncated
  • bc79afb Merge pull request #186 from jamhall/fix-listobjects-bucket-name
  • d0b74a8 fix(listObjects): Include correct IsTruncated value in response
  • 325ca7f fix(listObjects): Include bucket name in XML response
  • d69913a chore(deps): update dependency aws-sdk to v2.209.0
  • 1e152e2 Merge pull request #182 from jamhall/n1ru4l-patch-1
  • 84187d2 Merge pull request #177 from jamhall/co-mocha
  • fc7a12f refactor(test): Use co-mocha for async tests
  • b887fb0 Use getter instead fo inline cast
  • 8739779 Merge pull request #183 from n1ru4l/upstream/n1ru4l-patch-1
  • 3283b62 Cast to date before formatting

There are 25 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Problem using GM options and ACL

I don't understand how to use options and ACL permission. Here, in this example, options are not working (image is uploaded, but nothing is resized) and ACL doesn't set public-read for the uploaded file. Any idea why? Thanks.

var avatar = multer({
    storage: imager(
        {
            accessKeyId: process.env.AWSAccessKeyId,
            secretAccessKey: process.env.AWSSecretKey,
            region: process.env.AWSregion,
            bucket: 'my-bucket',
            dirname: 'images',
            filename: function (req, file, cb) {
                cb(null, req.user._id + ".png");
            },
            gm: {
               pool: 5,
               format: 'png',
               scale: {
                 width: 200,
                 height: 200,
                 type: 'contain'
               },
               crop: {
                 width: 200,
                 height: 200,
                 x: 0,
                 y: 0
               },
               rotate: 'auto'
            },
            s3 : {
                Metadata: {
                    "x-amz-acl": "public-read"
                }
            }
    })
});

I think nothing is transmitted, neither gm options, nor s3 Metadata.

An in-range update of mime is breaking the build 🚨

Version 2.0.5 of mime was just published.

Branch Build failing 🚨
Dependency mime
Current Version 2.0.3
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

mime is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 15 commits ahead by 15, behind by 1.

  • 25141e4 chore(release): 2.0.5
  • f14ccb6 fix: ES5 support (back to node v0.4)
  • ab5238a 2.0.4
  • b94c4ab changelog
  • 175cd7c mime-score -> dev dependency
  • 8cc0f4f Remove vestigial getScore() method
  • 852b042 Merge branch 'master' of github.com:broofa/node-mime
  • f548916 use mime-score module for resolving extension contentions. Fixes #182
  • 34b5c6b Link to 1.x version of docs
  • 6e7b9bb Merge pull request #177 from JuanjoSalvador/patch-1
  • 18cad2e Fixed markdown mistakes
  • 786a9bf readme_js.md
  • 453725b Correct wzrd.in usage
  • 36de668 2.0.3
  • 1dcef8a changelog

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.