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

225
Vistas
Cannot resolve nodejs files path on exported to another directory

I have a problem with display file path because not sure why but node is unable to display it.

If I am using req.file.filename it is working just fine but I need to process the loaded file so when I am exporting to a directory I need to use something like the second variable FILE_OUTPUT and in that case the path is not recognised anymore, any idee why is behaving like that?

The path is looking like: /Users/jimmy/work/task/running/public/output/xs_1634558545319.png and should be : output/xs_1634558545319.png

app.post("/exit", upload.single("pic"), function (req, res, next) {

  const FILE_INPUT = path.join(__dirname, req.file.path) ;

  const FILE_OUTPUT = path.join(__dirname, `/public/output/xs_${req.file.filename}`); ;
  
  im.convert([FILE_INPUT, '-resize', '100x100', FILE_OUTPUT], 
  function(err, stdout){
    if (err) throw err;

    console.log('stdout:', stdout, FILE_OUTPUT, FILE_INPUT);

  });
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you need to use path.basename:

const FILE_OUTPUT = path.basename(`/public/output/xs_${req.file.filename}`);
about 4 years ago · Juan Pablo Isaza Denunciar
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