Skip to content

Instantly share code, notes, and snippets.

@onejohi
Last active September 18, 2019 19:35
Show Gist options
  • Save onejohi/e786e9a5e89526b545e1cebbe146e1ad to your computer and use it in GitHub Desktop.
Save onejohi/e786e9a5e89526b545e1cebbe146e1ad to your computer and use it in GitHub Desktop.
const express = require('express')
const BusBoy = require('busboy')
const path = require('path')
const os = require('os')
const fs = require('fs')
const app = express()
app.post('/', (req, res) => {
const busboy = new BusBody({ headers: req.headers })
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
const saveTo = path.join(os.tmpDir(), path.basename(fieldname))
file.pipe(fs.createWriteStream(saveTo))
}).on('finish', () => {
res.json({ ok: true })
})
})
app.listen(process.env.PORT || 8080, () => {
console.log('server running on port 8080')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment