app.js
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var express = require('express');
var bodyParser= require('body-parser');//post할때 필요
var multer = require('multer'); //업로드할 때 필요
var request = require('request');
var app=express();
var _storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다.
destination: function (req, file, cb) {
cb(null, 'uploads/');//업로드 위치를 저장하는 path함수
},
filename: function (req, file, cb) {
// cb(null, file.originalname); //저장할 파일명
cb(null, 'mypic.jpg');
}
})
var upload = multer({ storage: _storage})
app.locals.pretty = true;
app.engine('html', require('ejs').renderFile);
app.use(express.static('public'));
app.use('/user',express.static('uploads'));
app.set('views','./views');
app.set('view engine', 'html');
app.use(bodyParser.urlencoded({extended:false}));
app.get('/home', function(req,res){
console.log("home");
res.render('upload');
});
/*app.post('/uploads',upload.single('userfile'),function(req,res){
upload(req,res,function(err) {
if(err) {
return res.end("Error uploading file.");
}
res.end("File is uploaded");
});
console.log(req.file);
res.render('facedetection');
})*/
app.post('/uploads', upload.single('userfile'),function(req,res){
console.log("uploads");
console.log(req.file);
res.render('facedetection');
});
app.listen(8080, function(){
console.log("connnected, 8080 port!");
});