48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
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/form2.html'))
|
|
})
|
|
|
|
app.post('/process_upload', function (req, res) {
|
|
let formularz = formidable({
|
|
multiples: true,
|
|
keepExtensions: true
|
|
})
|
|
|
|
formularz.uploadDir = __dirname + '/static/upload/'
|
|
|
|
formularz.parse(req, function (err, fields, files) {
|
|
let info = {
|
|
"date": fields.date,
|
|
"nazwa": fields.nazwa
|
|
}
|
|
|
|
let daneplikow = []
|
|
|
|
for (let i = 0; i < files.wyslany_plik.length; i++) {
|
|
daneplikow.push({
|
|
"wyslany_plik": {
|
|
"size": files.wyslany_plik[i].size,
|
|
"path": files.wyslany_plik[i].path,
|
|
"name": files.wyslany_plik[i].name,
|
|
"type": files.wyslany_plik[i].type
|
|
}
|
|
})
|
|
}
|
|
|
|
res.send([info, daneplikow])
|
|
})
|
|
})
|
|
|
|
app.use(express.static('static'))
|
|
|
|
app.listen(PORT, function () {
|
|
console.log("start serwera na porcie " + PORT)
|
|
})
|