Created
November 23, 2021 01:08
-
-
Save jsinai/3b89ac84fe8fdeb2b0f844ec4007276b to your computer and use it in GitHub Desktop.
Example of a file upload server written in JavaScript. This is useful as e.g. a log upload service. The BrightSign player will upload log files to this server if the "ul" registry entry is set to point to this endpoint..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const multer = require('multer'); | |
const app = express(); | |
const storage = multer.diskStorage({ | |
destination: './uploads/', | |
filename: function(req, file, cb) { | |
cb(null, file.originalname); | |
} | |
}); | |
const upload = multer({ | |
storage: storage | |
}); | |
app.post('/upload', upload.single('file'), function(req, res) { | |
console.log(req.body); | |
res.json({ | |
error: null, | |
result: 'success' | |
}); | |
}); | |
const port = process.env.PORT || 3000; | |
app.listen(port, () => | |
console.log(`App is listening on port ${port}.`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment