-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (35 loc) · 1.11 KB
/
app.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
const uuidV4 = require('uuid/v4')
const express = require('express')
const app = express()
var cors = require('cors')
app.use(cors())
// var bodyParser = require('body-parser')
// app.use(bodyParser.json())
// app.use(bodyParser.urlencoded({ extended: true }))
let fs = require('fs')
let PDFParser = require("pdf2json")
let pdfParser = new PDFParser(this,1)
var formidable = require('formidable')
var http = require('http')
var util = require('util')
function process_request(req, res) {
var form = new formidable.IncomingForm()
form.parse(req)
form.on('fileBegin', function (name, file){
file.path = __dirname + '/uploads/' + file.name
})
form.on('file', function (name, file){
pdfParser.loadPDF(file.path)
})
pdfParser.on("pdfParser_dataReady", pdfData => {
rawTextContent = pdfParser.getRawTextContent()
filePath = __dirname + "/uploads/" + uuidV4() + ".txt"
fs.writeFile(filePath, pdfParser.getRawTextContent())
res.send({rawTextContent: rawTextContent})
res.end()
})
}
app.post('/', process_request)
app.listen(4567, function () {
console.log('Listening on port 4567.')
})