0
// dotenv
require('dotenv').config();
// Express
const express = require('express');
const router = express.Router();
// Models
const Model = require('../Models/property.js');
// Multer - Media processing
const multer = require('multer');
const {GridFsStorage} = require('multer-gridfs-storage');
const mongoURL = process.env.DATABASE_URL;
const storage = new GridFsStorage({ 
    url: mongoURL,
    file: (req, file) => {
        console.log("check: "+ file);
    }
});
const upload = multer({ storage });

// Post
const mediaUpload = upload.fields([{ name: 'thumbnail', maxCount: 1 }, { name: 'gallery', maxCount: 10 }, { name: 'videos', maxCount: 4 }]);
router.post('/post', mediaUpload, async (req, res) => {

Hi im trying to upload files containing images & videos with fields of thumbnail, gallery & videos. I have been trying to troubleshoot the error of being unable to read properties of undefined which would be the files, but I checked around and the given but its unable to read the id of the files uploaded.

Error: TypeError: Cannot read properties of undefined (reading '_id')

New contributor
Lim Jing Png is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0