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
27
28
29
30
|
import { auth } from "./passport";
import app from "$app";
import multer from "multer";
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, "uploads");
},
filename: async (req, file, cb) => {
const parts = file.originalname.split(".");
const ext = parts.length > 1 ? parts[parts.length - 1] : "bin";
cb(null, `${req.user.username}-${file.fieldname}.${ext}`);
}
});
export const upload = multer({
storage,
onFileUploadStart: (file, req, res) => {
console.log("CHECKING SIZE");
const maxSize = 32 * 1000 * 1000;
if (req.files.file.length > maxSize) {
return false;
}
}
});
app.post("/profile", auth, upload.single("squirt"), async (req, res) => {
let { filename } = req.file;
res.send({ filename });
});
|