44 lines
1018 B
JavaScript
44 lines
1018 B
JavaScript
const express = require("express")
|
|
const app = express()
|
|
const PORT = 3000
|
|
|
|
const path = require('path')
|
|
const formidable = require('formidable')
|
|
|
|
app.get("/", function (req, res) {
|
|
res.sendFile(path.join(__dirname, '/static/form1.html'))
|
|
})
|
|
|
|
app.post('/process_upload', function (req, res) {
|
|
let formularz = formidable({})
|
|
|
|
formularz.uploadDir = __dirname + '/static/upload/'
|
|
|
|
formularz.parse(req, function (err, fields, files) {
|
|
|
|
console.log(files)
|
|
|
|
let info = {
|
|
"date": fields.date,
|
|
"nazwa": fields.nazwa
|
|
}
|
|
|
|
let danepliku = {
|
|
"wyslany_plik": {
|
|
"size": files.wyslany_plik.size,
|
|
"path": files.wyslany_plik.path,
|
|
"name": files.wyslany_plik.name,
|
|
"type": files.wyslany_plik.type
|
|
}
|
|
}
|
|
|
|
res.send([info, danepliku])
|
|
})
|
|
})
|
|
|
|
app.use(express.static('static'))
|
|
|
|
app.listen(PORT, function () {
|
|
console.log("start serwera na porcie " + PORT)
|
|
})
|