display image from server

Vic
Vic 2 years ago
parent dc83ccf8f8
commit 7f83cb6d16

@ -38,6 +38,7 @@
"dependencies": {
"axios": "^0.25.0",
"express": "^4.17.2",
"path": "^0.12.7",
"sharp": "^0.29.3"
}
}

@ -1,10 +1,26 @@
import express from "express"
import path from "path"
import fs from "fs"
const image = express.Router();
image.get('/', (req, res) => {
res.send('Welcome to image route please add parametres in the url');
image.get('/',
async (req: express.Request, res: express.Response): Promise<void> => {
let filename = req.query.filename as string;
})
try {
let filePath = path.resolve("images/full", `${filename}.jpg`);
console.log('FILE PATH', filePath);
if (!fs.existsSync(filePath)) {
res.status(404).send("Image don't exist! Try another name");
return;
}
res.sendFile(filePath);
} catch (err) {
res.status(404).send(`An error occured`);
}
//res.send('Welcome to image route please add parametres in the url');
})
export default image;
Loading…
Cancel
Save