-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.ts
26 lines (22 loc) · 697 Bytes
/
router.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Request, Response } from "express";
import multer from "multer";
import { uploadFS } from "./firebase";
const router = require("express").Router();
router.get("/", (req: Request, res: Response) => {
res.render("./upload.ejs");
});
router.post("/upload", multer().single("file"), (req: any, res: Response) => {
const fileBuf = req.file.buffer;
const fileRef = `${process.env.UPLOAD_BUCKE}/${req.file.originalname}`;
uploadFS(fileRef, fileBuf)
.then(() => {
res.redirect("/success");
})
.catch((err: any) => {
res.send(err);
});
});
router.get("/success", (req: Request, res: Response) => {
res.send("upload success");
});
module.exports = router;