Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
'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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda