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

378
Views
Error de ENOENT de carga de volúmenes de Docker y Multer

¡primera pregunta + desarrollador junior aquí!

Entonces mi problema es: estoy desarrollando una API con nodejs/express + Docker y Multer donde quiero cargar archivos. Traté de configurar Docker lo mejor que pude, lo mismo para Multer y persistir los archivos cargados en un volumen, pero me sigue arrojando este error:

 { "errno": -13, "code": "EACCES", "syscall": "open", "path": "public/media/pictures/picture-1642414319690.jpg", "storageErrors": [] }

Aquí está mi configuración de middleware de carga Multer:

 const multer = require('multer'); const path = require('path'); // PICTURES // Picture storage path const storage = multer.diskStorage({ destination(req, file, cb) { cb(null, '/public/media/pictures'); }, filename: (req, file, cb) => { cb( null, `${file.fieldname}-${Date.now()}${path.extname(file.originalname)}` ); }, }); // Check pictures type const checkPicType = (file, cb) => { // Allowed ext const pictypes = /jpeg|jpg|png/; // Check ext const extname = pictypes.test(path.extname(file.originalname).toLowerCase()); // Check mime const mimetype = pictypes.test(file.mimetype); if (mimetype && extname) { return cb(null, true); } return cb('Error: Images only!'); }; // Picture upload options const picUpload = multer({ storage, limits: { fields: 5, fieldNameSize: 10, fieldSize: 2000, fileSize: 25000000, }, fileFilter(req, file, cb) { checkPicType(file, cb); }, }).single('picture'); module.exports = { picUpload, };

Mi método de carga en api/picture.js:

 router.post('/upload', (req, res) => { picUpload(req, res, (err) => { if (err) { return res.status(403).json(err); } return res.status(201).json({ path: `${req.protocol}://${req.hostname}:${PORT}/${req.file.path}`, }); }); });

y finalmente mi docker-compose :

 services: web: build: context: ./ target: dev volumes: - .:/src - uploaded-files:/src/public/media/files - uploaded-pictures:/src/public/media/pictures command: npm run start:dev ports: - "5000:5000" environment: NODE_ENV: development DEBUG: nodejs-docker-express:* postgres: image: postgres restart: always environment: - POSTGRES_USER=${DB_USER} - POSTGRES_PASSWORD=${DB_PASS} volumes: - postgres:/var/lib/postgresql/data ports: - '5432:5432' volumes: postgres: uploaded-files: uploaded-pictures:

Como dije, soy bastante docker y multer, así que si me perdí un archivo o algunas líneas para ayudarlo a comprender mejor, dígamelo.

¡Gracias!

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

0

Lo descubrí, era solo un error de ruta simple en el middleware (picUpload.js)

cb(null, ' /src /public/media/pictures');

 // Picture storage path const storage = multer.diskStorage({ destination(req, file, cb) { cb(null, '/src/public/media/pictures'); }, filename: (req, file, cb) => { cb( null, `${file.fieldname}-${Date.now()}${path.extname(file.originalname)}` ); }, });
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!