Created
February 10, 2019 14:40
-
-
Save Leodau/d6d83e18f3fdef77de041fbf650cf523 to your computer and use it in GitHub Desktop.
Upload a sound file in NODEJS
This file contains 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 fs = require('fs'); | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
const port = 3000; | |
app.use(bodyParser.json({ limit: '50mb' })); | |
app.use(bodyParser.raw({ type: 'audio/wav', limit: '50mb' })); | |
app.get('/', (req, res) => res.send('Hello World!')); | |
app.post('/upload', function (req, res) { | |
console.log("RECIEVED: ", req.body); | |
fs.writeFile('audio.wav', req.body, (err) => { | |
if (err) throw err; | |
console.log('The file has been saved!'); | |
}); | |
res.send("Ok"); | |
}); | |
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment