Skip to content

Commit c3606cd

Browse files
html page file upload
0 parents  commit c3606cd

File tree

595 files changed

+77870
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

595 files changed

+77870
-0
lines changed

index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const express = require('express');
2+
const app = express();
3+
const multer = require('multer')
4+
const upload = multer({ dest: 'uploads/' })
5+
const fs = require('fs');
6+
7+
const PORT = 8080;
8+
const imageDB = []; // don't use this in real project;
9+
// It should be in Database
10+
11+
app.use(express.static('public'));
12+
app.use(express.static('uploads'));
13+
14+
15+
app.post('/image', upload.single('avatar'), function (req, res, next) {
16+
// req.file is the `avatar` file
17+
// req.body will hold the text fields, if there were any
18+
console.log(req.file.filename);
19+
console.log(req.body);
20+
21+
fs.rename(`uploads/${req.file.filename}`,`uploads/${req.body.fullname}`,
22+
(err) => {
23+
if(err) {throw err}
24+
else{
25+
imageDB.push(req.body.fullname);
26+
res.send(`<image width="50%" src='/${req.body.fullname}'></image>`);
27+
28+
}
29+
})
30+
31+
})
32+
app.get('/images',(req,res)=>{
33+
let html = "";
34+
imageDB.forEach(image=>{
35+
html += `<image width="50%" src='/${image}'></image>`
36+
})
37+
res.send(html);
38+
})
39+
40+
41+
app.listen(PORT,()=>{
42+
console.log('server started at ' + PORT )
43+
})
44+
45+
46+

node_modules/.bin/mime

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/mkdirp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)