Spaces:
Sleeping
Sleeping
Mohamed Abu Basith
commited on
Commit
·
e0676fa
1
Parent(s):
b5c0ed7
multer update
Browse files- routes/profileUpdate.js +6 -22
routes/profileUpdate.js
CHANGED
@@ -22,34 +22,18 @@ function failedResponse(message) {
|
|
22 |
}
|
23 |
}
|
24 |
|
25 |
-
//Disk storage where image store
|
26 |
const storage = multer.diskStorage({
|
27 |
-
destination:
|
28 |
-
|
|
|
|
|
29 |
},
|
30 |
-
filename:
|
31 |
cb(null, file.originalname);
|
32 |
-
}
|
33 |
-
});
|
34 |
-
|
35 |
-
//Check the image formate
|
36 |
-
const fileFilter = (req, file, cb) => {
|
37 |
-
// reject a file
|
38 |
-
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
39 |
-
cb(null, true);
|
40 |
-
} else {
|
41 |
-
cb(null, false);
|
42 |
-
}
|
43 |
-
};
|
44 |
-
|
45 |
-
const upload = multer({
|
46 |
-
storage: storage,
|
47 |
-
limits: {
|
48 |
-
fileSize: 1024 * 1024 * 5
|
49 |
},
|
50 |
-
fileFilter: fileFilter
|
51 |
});
|
52 |
|
|
|
53 |
|
54 |
//Update profile and watch
|
55 |
router.post('/', upload.single('file'), async (req, res) => {
|
|
|
22 |
}
|
23 |
}
|
24 |
|
|
|
25 |
const storage = multer.diskStorage({
|
26 |
+
destination: (req, file, cb) => {
|
27 |
+
const uploadDir = path.join(os.tmpdir(), 'uploads'); // Use a temporary directory
|
28 |
+
fs.mkdirSync(uploadDir, { recursive: true }); // Create the directory if it doesn't exist
|
29 |
+
cb(null, uploadDir);
|
30 |
},
|
31 |
+
filename: (req, file, cb) => {
|
32 |
cb(null, file.originalname);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
},
|
|
|
34 |
});
|
35 |
|
36 |
+
const upload = multer({ storage, limits: { fileSize: 5 * 1024 * 1024 }, });
|
37 |
|
38 |
//Update profile and watch
|
39 |
router.post('/', upload.single('file'), async (req, res) => {
|