Skip to content

Commit 0c04341

Browse files
committed
many changes
1 parent d90a2a7 commit 0c04341

Some content is hidden

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

101 files changed

+16848
-5
lines changed

upload a file using multer/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const express=require('express');
22
const bodyparser=require('body-parser');
33
const path=require('path');
44
const multer=require('multer');
5-
const exphbs=require('express-handlebars');
5+
const ejs=require('ejs');
66

77
//defining storage
88
var storage=multer.diskStorage({
@@ -12,14 +12,15 @@ var storage=multer.diskStorage({
1212
filename: function(req,file,cb){
1313
cb(null,file.filename+ '-'+ Date.now());
1414
}
15-
})
15+
});
16+
17+
var upload=multer({storage : storage}).single('userPhoto');
1618

1719

1820
const app=express();
1921

2022
//set engine
21-
app.engine('handlebars',exphbs({ extname: "hbs", defaultLayout: false, layoutsDir: "views/ "}));
22-
app.set('view engine', 'handlebars');
23+
app.set('view engine', 'ejs');
2324

2425
//using json
2526
app.use(bodyparser.json());
@@ -30,9 +31,18 @@ app.use('/public',express.static(path.join(__dirname + 'public')));
3031

3132

3233
app.get('/',function(req,res){
33-
res.status(400).json({msg: "hyyy"});
34+
res.send('hy');
3435
})
3536

37+
app.post('/api/upload',function(req,res){
38+
upload(req,res,function(err){
39+
if(err){
40+
res.status(400).end('error');
41+
}
42+
res.status(200).end('file uploaded');
43+
})
44+
});
45+
3646
//port is live
3747
const port=3000|| process.env.PORT;
3848
app.listen(port,function(res,err){

upload a file using multer/node_modules/.bin/ejs

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

upload a file using multer/node_modules/.bin/ejs.cmd

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

upload a file using multer/node_modules/.bin/ejs.ps1

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

upload a file using multer/node_modules/.bin/jake

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

upload a file using multer/node_modules/.bin/jake.cmd

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

upload a file using multer/node_modules/.bin/jake.ps1

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

upload a file using multer/node_modules/async/.travis.yml

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

upload a file using multer/node_modules/async/LICENSE

Lines changed: 19 additions & 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)