forked from SinghVikram97/ScrapWala-Api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (42 loc) · 1.1 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
45
46
47
const express=require('express');
const cors=require('cors')
const bodyParser=require('body-parser')
const formidable=require('formidable')
const fs=require('fs');
const { PythonShell } = require("python-shell");
const app=express();
app.use(cors());
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json());
app.use(express.static('public'));
app.get('/',(req,res)=>{
res.send("Working")
})
app.post('/fileupload',(req,res)=>{
console.log('Post image');
let form=formidable.IncomingForm();
form.parse(req,(err,fields,files)=>{
let oldPath=files.filetoupload.path;
console.log(__dirname);
let newPath=__dirname+'/public/'+files.filetoupload.name;
fs.rename(oldPath,newPath,(err)=>{
if(err){
throw err;
}
let options={
args:[newPath]
}
PythonShell.run("label_image.py",options,(err,result)=>{
if(err){
throw err;
}
let category=result;
res.json(category);
})
})
})
})
const port = process.env.PORT || 8000;
app.listen(port,()=>{
console.log("Server started on localhost://8000")
})