How can I upload images to Cloudinary?

Follow

Comments

5 comments

  • Avatar
    Ryan Carville

    Hello,

     

    Was curious as to if you are able to upload images to a cloudinary name from a localhost?  I am in development and wanted to get all the fetch requests in pace before pushing it.

    Thanks from a rookie dev!

    0
    Comment actions Permalink
  • Avatar
    Shirly Manor

    Hey,

    You can just drag and drop your images to the media library. 

    Alternatively, you can use for example in NodeJs:

    const cloudinary = require("cloudinary");
    const fs = require("fs");

    cloudinary.config({
    cloud_name: "<my-cloud-name>",
    api_key: "<my-api-key>",
    api_secret: "<my-api-secret>"
    });

    fs.readdir(".", (err, files) => {
    files.forEach(fileName => {
    cloudinary.v2.uploader.upload(
    fileName,
    { folder: "test4",resource_type:'auto' },
    (err, fileResponse) => {
    if (err) console.log(err);
    console.log(fileResponse);
    }
    );
    });
    });


    Hope that helps,
    Shirly
    0
    Comment actions Permalink
  • Avatar
    Ryan Carville

    Thank you Shirly!

    I am using react so not sure if that is why but when I implement this I get the following error.  Looks like it is looking for a node version?  Any help is greatly appreciated.  

     

    {module.exports = Number(process.versions.node.split('.')[0]) < 8 ? __webpack_require__(/*! ./lib-es5/cloudinary */ "./node_modules/cloudinary/lib-es5/cloudinary.js")
    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi Ryan,

    The example that Shirly shared uses our NodeJS SDK, so you'll need to have that installed for it to import the cloudinary module from it. May I please ask if that's installed and also which NodeJS version you're using?

    You can install the cloudinary module by running "npm install cloudinary" from within your app directory.

    This section of our documentation describes in detail the configuration/installation and Cloudinary features you can access via the NodeJS SDK:

    https://cloudinary.com/documentation/node_integration

    If you encounter any issues with this, please send an email to support@cloudinary.com with a sample code or error you're seeing and we'll take a look for you.

    Best regards,

    Aleksandar

    0
    Comment actions Permalink
  • Avatar
    Ryan Carville

    Hello Aleksander,

     

    Thank you for the reply.  And yes I have already installed the Node.js package and still get the "split" error.  Will re-read the docs to ensure I am using it correctly.

     

    Also I am on 10.15.3 Node. 

    Ryan

    0
    Comment actions Permalink

Please sign in to leave a comment.