index.js
1.4 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
var express = require('express');
var router = express.Router();
var multer = require("multer");
var path = require("path");
var PythonShell = require('python-shell');
var spawn = require("child_process").spawn;
var storage = multer.diskStorage({
destination: function(req, file, callback) {
callback(null, "../deep_sort_yolov4/")
},
filename: function(req, file, callback) {
var extension = path.extname(file.originalname);
var basename = path.basename(file.originalname, extension);
callback(null, basename + extension);
}
})
// 1. multer 미들웨어 등록
var upload = multer({
storage: storage
})
// 뷰 페이지 경로
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
// 2. 파일 업로드 처리
router.post('/create', upload.single("File"), function(req, res) {
// 3. 파일 객체
var file = req.file;
var options = {
mode: 'text',
pythonPath: __dirname + '/../../venv/Scripts/python.exe',
pythonOptions: ['-u'],
scriptPath: __dirname + '/../../deep_sort_yolov4/',
args: [file.originalname]
};
var shell1 = new PythonShell.PythonShell('main.py', options);
shell1.end(function(err) {
if (err) throw err;
else {
res.render('result', { file_name: file.originalname.split('.')[0] });
}
});
});
module.exports = router;