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

398
Views
Error de la aplicación Express.js: no se pueden leer las propiedades de undefined (leyendo 'transfer-encoding'

Estoy trabajando en una API de aplicación de blogs con express y MongoDB.

Estoy tratando de agregar una imagen de publicación para cada publicación de blog. Siendo nuevo para expresar, me encontré con este problema.

Y recibí este error: No se pueden leer las propiedades de undefined (leyendo 'codificación de transferencia'

Aquí está el código del código del controlador de correos:

 const asyncHandler = require("express-async-handler"); const imageModel = require("../models/imageModel"); const User = require("../models/userModel"); const Post = require("../models/postModel"); // storage const Storage = multer.diskStorage({ destination: "storage", filename: (res, req, file, cb) => { cb(null, Date.now() + file.originalname); }, }); const upload = multer({ storage: Storage, }).single("img"); // @desc Create a new post // @route POST /api/posts/ // @access Private const createPost = asyncHandler(async (res, req) => { let img; upload(req, res, async function (err) { if (err) { res.status(400); throw new Error("Error uploading images."); } const newImage = await new imageModel({ img: { data: req.file.filename, contentType: "image/png", }, }); newImage.save().then(console.log("Successfully uploaded")); img = newImage; }); console.log(img); const { title, description, categories, nacCompatible, downloadURL } = req.body; if (!title || !description || !categories || !downloadURL) { res.status(400); throw new Error("Please add all the required fields."); } // Get user using the id in the JWT const user = await User.findById(req.user.id); if (!user) { res.status(401); throw new Error("User not found"); } const post = await Post.create({ title, description, img, categories, nacCompatible, downloadURL, user: req.user._id, status: "new", }); res.status(201).json(post); });

También tengo const multer = require("multer"); en la parte superior del controlador.

La función de creación de publicaciones funcionó bien hasta que intenté agregar esta función de carga de imágenes.

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

0

Esta línea: "createPost = asyncHandler(async (res, req) "

Pones el req y res en el orden incorrecto

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!