Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
'multer-s3-transform' gives TypeError: Cannot read property 'length' of undefined on uploading a file larger than given the limit

I've been trying to upload image with transform using this package. but I don't want to upload file larger than 1MB in size. So, I've set my multer as following,

const storage = multerS3Transform({
  s3: s3,
  bucket:
    process.env.AWS_BUCKET_NAME +
    process.env.UPLOADS_DIRECTOY +
    process.env.FOLDER_DIRECTOY,
  shouldTransform: function (req, file, cb) {
    cb(null, /^image/i.test(file.mimetype));
  },
  transforms: [
    {
      id: "original",
      key: function (req, file, cb) {
        cb(null, `${Date.now()}${path.extname(file.originalname)}`);
      },
      transform: function (req, file, cb) {
        cb(null, sharp());
      },
    },
    {
      id: "md",
      key: function (req, file, cb) {
        cb(null, "md/" + `${Date.now()}${path.extname(file.originalname)}`);
      },
      transform: function (req, file, cb) {
        cb(null, sharp().resize(imgSize[0].width, imgSize[0].height));
      },
    },
    {
      id: "lg",
      key: function (req, file, cb) {
        cb(null, "lg/" + `${Date.now()}${path.extname(file.originalname)}`);
      },
      transform: function (req, file, cb) {
        cb(null, sharp().resize(imgSize[1].width, imgSize[1].height));
      },
    },
  ],
});

const upload = multer({
  storage,
  limits: { fileSize: 1000000 }, //1000000 bytes = 1MB
  fileFilter: function (req, file, cb) {
    checkFileType(file, cb);
  },
});

When I upload files smaller than 1MB, It works fine. If I give a file larger than 1MB, it should give me MulterError with LIMIT_FILE_SIZE code. But it gives me TypeError: Cannot read property 'length' of undefined

this is the error stack

TypeError: Cannot read property 'length' of undefined
    at FileAppender.removePlaceholder (D:\mirasel\Test_project\node_modules\multer\lib\file-appender.js:48:49)
    at D:\mirasel\Test_project\node_modules\multer\lib\make-middleware.js:147:22
    at ManagedUpload.callback (D:\mirasel\Test_project\node_modules\multer-s3-transform\index.js:400:29)
    at ManagedUpload.cleanup (D:\mirasel\Test_project\node_modules\aws-sdk\lib\s3\managed_upload.js:635:10)
    at Sharp.<anonymous> (D:\mirasel\Test_project\node_modules\aws-sdk\lib\s3\managed_upload.js:187:44)
    at Sharp.emit (events.js:400:28)
    at Sharp.emit (domain.js:470:12)
    at Object.<anonymous> (D:\mirasel\Test_project\node_modules\sharp\lib\output.js:1075:18)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!