-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridFs.js
38 lines (32 loc) · 980 Bytes
/
gridFs.js
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
31
32
33
34
35
36
37
38
const crypto = require("crypto");
const { GridFsStorage } = require('multer-gridfs-storage');
const { mongoURI } = require('./db')
const multer = require("multer");
const path = require("path");
// Storage
const storage = new GridFsStorage({
url: mongoURI,
file: (req, file) => {
console.log(file);
return new Promise((resolve, reject) => {
crypto.randomBytes(16, (err, buf) => {
if (err) {
return reject(err);
}
const filename = buf.toString("hex") + path.extname(file.originalname);
const fileInfo = {
filename: filename,
bucketName: "uploads"
};
resolve(fileInfo);
});
});
}
});
const upload = multer({
storage,
limits: {
fileSize: 30 * 1024 * 1024, // 30MB
},
});
module.exports = { upload, limits: { fileSize: 50 * 1024 * 1024 } }