-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.js
32 lines (28 loc) · 845 Bytes
/
Server.js
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
var express = require("express");
var bodyParser = require("body-parser");
var multer = require('multer');
var app = express();
app.use(bodyParser.json());
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './photos');
},
filename: function (req, file, callback) {
callback(null, file.fieldname + '-shoes-photo-' + Date.now());
}
});
var upload = multer({ storage : storage }).array('photo',2);
app.get('/',function(req,res){
res.sendFile(__dirname + "/index.html");
});
app.post('/api/photo',function(req,res){
upload(req,res,function(err) {
if(err) {
return res.end("Error uploading photo.");
}
res.end("photo is uploaded");
});
});
app.listen(3000,function(){
console.log("Server is started on port 3000");
});