const express = require('express');
const cors = require('cors');
const multer = require("multer");
const fs = require("fs");
const path = require("path");
app.get('/imagen/:file', (req, res) => {
//Se recoge el parametro "file"
let file = req.params.file;
// Ruta de la imagen en el sistema de archivos
let filepath = "./uploads/images/" + file;
//let filepath = "./rutaCarpetaImagenes/" + file;
//comprobar si existe el fichero
fs.stat(filepath, (error,exists) => {
if (!error && exists){
return res.sendfile(path.resolve(filepath));
}else{
return res.status(404).send({
status: 'error',
data: 'imagen no existe',
file: req.file
});
}
});
});
El ejemplo anterior es bastante sencillo. Simplemente es para mostrar como se hace.