question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

shouldTransform being skipped

See original GitHub issue
const s3 = new AWS.S3();
const maxSize = 5 * 1000 * 1000;
/* TODO Resize */
const multerOptions = {
  storage: multerS3({
    s3: s3,
    bucket: process.env.AWS_BUCKET,
    bucketPath: 'images',
    acl: 'public-read',
    limits: {
      fileSize: maxSize,
      files: 5,
      fields: 5,
    },
    contentType: multerS3.AUTO_CONTENT_TYPE,
    key: function(req, file, cb) {
      const extension = file.mimetype.split('/')[1]; // gets the extension
      const area = req.body.area;
      fileName = `${area}${uuid.v4()}.${extension}`;
      cb(null, fileName);
    },
    shouldTransform: function(req, file, cb) {
      cb(null, /^image/i.test(file.mimetype));
    },
    transforms: [
      {
        id: 'original',
        transform: function(req, file, cb) {
          //Perform desired transformations
          cb(
            null,
            sharp()
              .resize(600, 600)
              .max()
          );
        },
      },
    ],
  }),
  fileFilter(req, file, next) {
    const isPhoto = file.mimetype.startsWith('image/');
    if (isPhoto) {
      next(null, true); // null for error means it worked and it is fine to continue to next()
    } else {
      next({ message: 'Fotos: Tipo de arquivo não suportado!' }, false); // with error
    }
  },
};

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

This is my temp code, trying to have the resize to work. I tried many different codes but it doesn’t look like the transforms array is being loaded at all. Is there a way I can call sharp() earlier and have multer upload the resized images to s3 then?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kerubkimcommented, Jan 24, 2020

I have installed multer-s3-transform but shouldTransform is still being skipped? I have been trying to figure this out for a while now. Help?

2reactions
lschwecommented, Jan 4, 2019

o u gotta use this npm install multer-s3-transform

Read more comments on GitHub >

github_iconTop Results From Across the Web

multers3 skipping shouldTransform - node.js - Stack Overflow
My issue is in my multerS3 options shouldTransform is being skipped hence not taking the transforms. Here is my entire file of upload...
Read more >
multer-s3-transform - npm
Streaming multer storage engine for AWS S3. This project is mostly an integration piece for existing code samples from Multer's storage ...
Read more >
Why You Should Transform to Summon Shenron! Dragon Ball ...
I always tell you to transform when summoning Shenron... I should follow that advice myself.This is gameplay footage for Dragon Ball the ...
Read more >
How financial services boards should transform sustainable ...
Financial services boards are quickly realizing that narrow oversight of sustainable finance is no longer suitable.
Read more >
10 reasons you should transform your career - Accenture
Select "Life at Accenture" on the registration form. Already registered? Sign in to manage your subscriptions. Let there be change.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found