Last active
September 18, 2019 19:35
-
-
Save onejohi/e786e9a5e89526b545e1cebbe146e1ad to your computer and use it in GitHub Desktop.
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 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