whenever i try to upload file in cloudinary it does not complete and throw a error

chandra
chandra Member Posts: 1
edited July 2023 in Developer APIs

//code

require("dotenv").config();


const cloudinary = require("cloudinary").v2;

const { CloudinaryStorage } = require("multer-storage-cloudinary");


//configure cloudinary

cloudinary.config({

  cloud_name: process.env.CLOUDINARY_NAME,

  api_key: process.env.CLOUDINARY_KEY,

  api_secret: process.env.CLOUDINARY_SECRET,

});


//instance of cloudinary storage

const storage = new CloudinaryStorage({

  cloudinary,

  allowedFormats: ["jpg", "png", "jpeg"],

  params: {

    folder: "first-blog",


    transformation: [{ width: 1980, height: 1980, crop: "limit" }],

  },

});


module.exports = storage;


//error

{

 "message": "Socket connection timeout",

 "status": "Failed",

 "stack": "Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout\n  at new NodeError (node:internal/errors:399:5)\n  at internalConnectMultiple (node:net:1099:20)\n  at Timeout.internalConnectMultipleTimeout (node:net:1638:3)\n  at listOnTimeout (node:internal/timers:575:11)\n  at process.processTimers (node:internal/timers:514:7)"

}

Tagged:

Answers

  • Tamara
    Tamara Member, Cloudinary Staff Posts: 123

    Hi there,

    Thanks for reaching out.

    Most likely this is an issue with your connection, or with something between your application environment and the server you're connecting to, but the error alone isn't enough to determine that - are you able to see more about the reason for the failure?

    You may refer to this documentation on how to integrate Cloudinary SDK with Next JS. And for additional reference, see https://spacejelly.dev/posts/how-to-programmatically-upload-images-to-cloudinary-in-react-next-js/

    Also, if you're experiencing difficulty integrating Cloudinary within an on-premises platform or behind a firewall, there may be a couple of possible solutions you can try:

    • Whitelist res.cloudinary.com on your firewall.
    • Deliver your Cloudinary resources using a CNAME. Instead of res.cloudinary.com, you would use a custom domain such as images.mydomain.com. It's worth bearing in mind that there may be additional cost involved, as this option is only available Advanced plan ($249/month) and higher. If you need to delivery your CNAME via HTTPS, it would require an SSL certificate for an additional fee.

    I hope this helps. Please let me know how would you like to proceed.

    Best regards,

    Tamara