Skip to content

Instantly share code, notes, and snippets.

@jsinai
Created November 23, 2021 01:08
Show Gist options
  • Save jsinai/3b89ac84fe8fdeb2b0f844ec4007276b to your computer and use it in GitHub Desktop.
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..
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