-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (32 loc) · 1.04 KB
/
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
39
40
41
42
43
44
var path = require("path");
var express = require("express");
var multer = require("multer");
var Unzipper = require("decompress-zip");
var app = express();
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './src/uploaded');
},
filename: function (req, file, callback) {
callback(null,file.originalname);
}
});
app.use(multer({storage : storage}).single('upload_file'));
app.get('/',function(req,res){
res.sendFile(__dirname + "/upload.html");
});
app.post("/", function(req, res){
if (req.file){
var filepath = path.join(req.file.destination, req.file.filename);
var unzipper = new Unzipper(filepath);
var filename = function (req, file, callback) {
callback(null,file.originalname);
}
unzipper.on("extract", function () {
console.log("Finished extracting");
});
unzipper.extract({ path: "C://Test/Extract"});
}
res.status(204).end();
});
app.listen(3000);