Socket Connection Timeout
i'm getting socket timeout every time even when my connection is alright and my cloudinary config is correct, what every type of code i write i get this issue
i'm providing my code down here please review this and help me
i'm using multer and cloudinary
this is my multer code
const multer= require('multer');
const storage = multer.memoryStorage();
const fileFilter=(req,file,cb) =>{ if(file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/gif'){ cb(null,true); }else{ cb(new Error("Invalid file type. Only JPEG, PNG, and GIF files are allowed"), false); }}
const upload=multer({ storage, limits:{ fileSize : 1024 * 1024 * 1 }, fileFilter: fileFilter})
module.exports= upload
this is my cloudinary code
const cloudinary=require('cloudinary').v2;const ApiErrors=require('../../utils/ApiResponse/ApiErrors')
const fs=require('fs');
cloudinary.config({ cloud_name:"*********", api_key:"*********", api_secret:"*********", // log_level: "debug" });
const uploadOnCloudinary = async (buffer) => { try { if (!buffer) { console.log("No buffer provided"); return null; } return new Promise((resolve, reject) => { const uploadStream = cloudinary.uploader.upload_stream({ resource_type: "auto", timeout: 30000 }, (error, result) => { if (error) { console.error("Upload error:", error); // Log only the message return reject(new Error(`Upload failed,${error.message}`)); } resolve(result); }); uploadStream.end(buffer); }); } catch (error) { console.error("Upload error:", error); }
module.exports={ uploadOnCloudinary}
this is my route
router.post('/add/warehouse',verifyToken.verify,verifyRole('WAREHOUSE'),upload.fields([{name:"wareHouseImage", maxCount:5}]),warehouseController.AddWareHouse);
this is my controller
if (req.files && req.files.wareHouseImage && req.files.wareHouseImage.length > 0) { // Iterate over each uploaded file await Promise.all( req.files.wareHouseImage.map(async (file) => {
const dataUriString = DataURIParser.format(path.extname(file.originalname).toString(), file.buffer);
uploadResult = await uploadOnCloudinary(dataUriString.content); if (uploadResult && uploadResult.url) { imageURL.push(uploadResult.url); }
}) ); } else { return next(ApiErrors(400, "No file uploaded. Please upload some pictures")); }