Skip to content

Instantly share code, notes, and snippets.

@killtheliterate
Created September 4, 2017 23:05
Show Gist options
  • Save killtheliterate/4e0417afad44958d4706bf47e5f5ae74 to your computer and use it in GitHub Desktop.
Save killtheliterate/4e0417afad44958d4706bf47e5f5ae74 to your computer and use it in GitHub Desktop.
const Router = require('koa-router')
const body = require('koa-body')
const fs = require('fs')
const router = new Router()
const BASE_URL = '/upload'
router.put(BASE_URL, body({ multipart: true }), async (ctx) => {
const files = ctx.request.body.files
const keys = Object.keys(files)
keys.forEach(key => {
const file = files[key]
const reader = fs.createReadStream(file.path)
const writer = fs.createWriteStream(/* s3 */)
reader.pipe(writer)
})
ctx.status = 200
ctx.body = {
message: 'good jorb, budz'
}
})
module.exports = router
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment