-
Notifications
You must be signed in to change notification settings - Fork 0
/
filehandler.js
39 lines (35 loc) · 1.12 KB
/
filehandler.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
const path = require('path');
const express = require('express');
const multer=require('multer');
const upload_folder = `${__dirname}/uploads/`;
const filehandler=express.Router();
const storage=multer.diskStorage({
destination:(req,file,cb)=>{
cb(null,upload_folder);
},
filename:(req,file,cb)=>{
cb(null,file.originalname);
}
});
var upload = multer({
storage:storage,
dest: upload_folder,
limits:{
fileSize: 5000000
},
fileFilter: (req, file, cb) => {
if (file.mimetype == "image/png" || file.mimetype == "image/jpg" || file.mimetype == "image/jpeg") {
cb(null, true);
} else {
cb(null, false);
return cb(new Error('Only .png, .jpg and .jpeg format allowed!'));
}
}
});
filehandler.post("/",upload.single("dp"),(req,res)=>{
// console.log(req.query.to);
req.socket.to(req.query.to).emit("takefile",req.file.originalname,req.query.to,req.query.from,req.query.from);
req.socket.to(req.query.from).emit("takefile",req.file.originalname,req.query.from,req.query.to,req.query.from);
res.json({err:"no error"});
})
module.exports=filehandler;