Last active
November 1, 2020 22:38
-
-
Save mbrown3321/6060a218ab428fa16fa634bab7620b38 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 router = express.Router(); | |
const models = require("../models"); | |
router.get("/uploads", async (req, res) => { | |
let uploadList = await models.uploads.findAll(); | |
uploadList = uploadList.map(item => { | |
let buff = new Buffer(item.image, "base64"); | |
let encoded = buff.toString("ascii"); | |
return { | |
...item.toJSON(), | |
image: encoded | |
}; | |
}); | |
res.send(uploadList); | |
}); | |
router.post("/uploads", async (req, res) => { | |
await models.uploads.create({ | |
file_name: req.body.file_name, | |
image: req.body.image | |
}); | |
res.sendStatus(201); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment