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

127
Views
JavaScript: acceder al objeto dentro de una matriz dentro del objeto usando multer

Aquí está mi función multer:

 const storage = multer.diskStorage({ destination: (req, file, callback) => { let type = req.params.type; let path = `./data/${type}`; fs.mkdirsSync(path); callback(null, path); }, filename: (req, file, cb) => { const ext = mime.extension(file.mimetype); const random = Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000; cb(null, `${Date.now()}-${random}.${ext}`); }, });

Aquí está el enrutador: router.post("/", auth, multer({ storage }).fields([{ name: 'image', maxCount: 1 }, { name: 'video', maxCount: 1 }]), addMovie); Esto es lo que obtengo cuando estoy en console.log(req.files) -

 [Object: null prototype] { image: [ { fieldname: 'image', originalname: '����� ����.png', encoding: '7bit', mimetype: 'image/png', destination: './data/undefined', filename: '1631293039713-7613.png', path: 'data\\undefined\\1631293039713-7613.png', size: 13133 } ], video: [ { fieldname: 'video', originalname: 'file_example_MP4_480_1_5MG.mp4', encoding: '7bit', mimetype: 'video/mp4', destination: './data/undefined', filename: '1631293039720-3601.mp4', path: 'data\\undefined\\1631293039720-3601.mp4', size: 1570024 } ] }

Estoy enviando una imagen y un video. Quiero acceder a los campos dentro de los objetos. Y no estoy seguro de cómo hacerlo.

Intenté eso: req.files.image[0] y ese es el error: Property 'image' does not exist on type '{ [fieldname: string]: File[]; } | File[]'. Property 'image' does not exist on type 'File[]'.ts(2339)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes probar (req as any).files.image[0] . Es un poco complicado con los tipos de requisitos req

about 4 years ago · Juan Pablo Isaza Report
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!