-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (31 loc) · 916 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
33
34
35
36
37
38
const express = require('express');
const multer = require('multer');
let app = express();
let storage = multer.diskStorage({
destination: function(req, file, callback) {
callback(null, './uploads');
},
filename: function(req, file, callback) {
callback(null, 'file-' + file.fieldname + '-' + Date.now() + '.pdf');
}
});
let upload = multer({ storage }).single('pdf');
app.get('/', function(req, res) {
console.log('Home...')
res.sendFile(__dirname + "/index.html");
});
app.post('/up/pdf', function(req, res) {
console.log('Uploading...')
upload(req, res, function(err) {
if (err) {
console.log('Failed');
res.end('Failed!');
}
console.log('Uploaded');
res.end('Success!');
//res.redirect('/')
});
});
app.listen(3000, function() {
console.log('Listening: http://localhost:3000/ ');
});