Skip to content

Instantly share code, notes, and snippets.

@maticzav
Last active January 17, 2018 19:59
Show Gist options
  • Save maticzav/646c9b32ea147a5a183420e1c556f85b to your computer and use it in GitHub Desktop.
Save maticzav/646c9b32ea147a5a183420e1c556f85b to your computer and use it in GitHub Desktop.
// src/modules/fileApi.ts
import * as multiparty from 'multiparty'
let form = new multiparty.Form()
form.on('part', async function(part) {
if (part.name !== 'data') {
return
}
const name = part.filename
const secret = uuid()
const size = part.byteCount
const contentType = mime.lookup(part.filename)
try {
// Upload to S3
// Sync with Prisma
return res.status(200).send(file)
} catch (err) {
console.log(err)
return res.sendStatus(500)
}
})
form.on('error', err => {
console.log(err);
return res.sendStatus(500)
})
form.parse(req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment