display image from server
parent
dc83ccf8f8
commit
7f83cb6d16
@ -1,10 +1,26 @@
|
|||||||
import express from "express"
|
import express from "express"
|
||||||
|
import path from "path"
|
||||||
|
import fs from "fs"
|
||||||
|
|
||||||
const image = express.Router();
|
const image = express.Router();
|
||||||
|
|
||||||
image.get('/', (req, res) => {
|
image.get('/',
|
||||||
res.send('Welcome to image route please add parametres in the url');
|
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;
|
export default image;
|
Loading…
Reference in New Issue