Skip to content

Instantly share code, notes, and snippets.

@mbrown3321
Last active November 1, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrown3321/6060a218ab428fa16fa634bab7620b38 to your computer and use it in GitHub Desktop.
Save mbrown3321/6060a218ab428fa16fa634bab7620b38 to your computer and use it in GitHub Desktop.
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