Last active
January 17, 2018 19:59
-
-
Save maticzav/646c9b32ea147a5a183420e1c556f85b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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