-
Notifications
You must be signed in to change notification settings - Fork 0
/
multer.js
48 lines (38 loc) · 1.03 KB
/
multer.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
39
40
41
42
43
44
45
46
47
const multer=require('multer')
const path=require('path')
// const storage=multer.diskStorage({
// destination:function(req,file,cb){
// cb(null,'/uploads')
// },
// filename:function (req,file,cb)
// {
// cb(null,new Data().toIOString()+'-'+file.originalname)
// }
// })
// //file validation
// const fileFilter=(req,file,cb)=>{
// if(file.mimetype==='image/jpeg' || file.mimetype==='image/png')
// {
// cb(null,true)
// }else
// {
// //orevent to upload
// cb({message:'Unsupported file format'},false)
// }
// }
// const upload=multer({
// storage:storage,
// limits:{fileSize:1024*1024},
// fileFilter:fileFilter
// })
module.exports = multer({
storage:multer.diskStorage({}),
fileFilter:(req,file,cb)=>{
let ext=path.extname(file.originalname);
if(ext !== '.jpg' && ext !=='.jpeg' && ext !=='.png'){
cb(new Error('file type is not supported'),false);
return;
}
cb(null,true);
}
});