Sindbad~EG File Manager
const { v2: cloudinary } = require("cloudinary");
const { CloudinaryStorage } = require("multer-storage-cloudinary");
const multer = require("multer");
const path = require("path");
const fsPromises = require("fs").promises;
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads/");
},
filename: function (req, file, cb) {
cb(
null,
file.fieldname + "-" + Date.now() + path.extname(file.originalname)
);
},
});
// // Configuring your Cloudinary credentials
// cloudinary.config({
// cloud_name: process.env.CLOUD_NAME,
// api_key: process.env.API_KEY,
// api_secret: process.env.API_SECRET,
// });
// // Setting up Cloudinary storage for multer
// const storage = new CloudinaryStorage({
// cloudinary: cloudinary,
// params: {
// folder: "your_folder_name", // The name of the folder in cloudinary
// allowed_formats: ["jpg", "png"], // supports the following file formats by default: jpg, png, gif, webp, bmp, flif, heic, svg, pdf, tiff, mp4 (It depends on your Cloudinary plan)
// // You can add more parameters here based on your requirements.
// },
// });
const upload = multer({ storage: storage });
const deleteImageFromLocal = async (fileName) => {
try {
await fsPromises.unlink(path.join("./", "uploads", fileName));
return true;
} catch (error) {
console.log(`warning message:${error}`);
}
};
module.exports = { upload, deleteImageFromLocal };
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists