Cloudinary upload configuration help

I am attempting to configure Cloudinary as my upload provider for production however, I am receiving an error when uploading an image.

Error: “An internal server error occurred”

This is my provider config at ./config/plugins.js
I have my env variables set and the strapi-provider-upload-cloudinary installed.
node: 12.18.2
npm: 6.14.6
strapi: 3.2.4

module.exports = ({ env }) => {
  if (env("NODE_ENV") === "production") {
return {
  upload: {
    provider: 'cloudinary',
    providerOptions: {
      cloud_name: env('CLOUDINARY_NAME'),
      api_key: env('CLOUDINARY_KEY'),
      api_secret: env('CLOUDINARY_SECRET'),
    }
  }
}
  }
  // ...
};

My feeling is that my configuration for Cloudinary is missing something however, I’m not able to figure out what. Any help is much appreciated

Can you please share logs for that error?

Here are the heroku logs. I have double-checked that my api key is configured correctly in my .env file. I’m not sure where to debug from here. Thanks for your help

I issue ended up being I did not set my env variables in Heroku. I only had the env vars set locally in my .env file :sweat_smile:

3 Likes

Hi, I got the same issue here. Could you share what env variables you needed to set in Heroku? Thanks!

Hi @AndRew_SIT, I believe there are two ways to add environment variables to Heroku.

  1. Through your apps Heroku dashboard.
  2. Through the Heroku CLI.

Dashboard
In your Heroku app, click on “Settings”. Then scroll to the “Config Vars” section and you will see a button labeled “Reveal Config Vars.” This is where you should add your environment variables for Strapi (Cloudinary vars, database vars, and others).

CLI
Here is the Strapi doc for the Heroku database set up. It’s essentially the same process for setting the Cloudinary vars. See #7 “Heroku database set up”.

So what I set as vars in Heorku were my Cloudinary KEY, NAME, and SECRET.

Just a bit more context for others…
Local set up
If I understand this all correctly, the dotenv file will only be used to read my vars in non-production environments (i.e. locally). Dotenv files get .gitignore’d during deployment.

Production set up
Therefore if we set up the Cloudinary vars in Heroku’s production server, Strapi will have the configuration necessary to connect to Cloudinary in production.

1 Like

@vnn8248 Thanks for your prompt reply and being helpful!

I still can’t figure out what are the names of the necessary env variables. They aren’t in the documentation. I have tried something like CLOUDINARY_API_KEY, CLOUDINARY_URL, CLOUDINARY_API_SECRET, but didn’t work.

I’d appreciate it if you could tell me more details.

./config/plugins.js:

module.exports = ({env}) => {
    //...
        upload: {
            provider: 'cloudinary',
            providerOptions: {
                cloud_name: env('CLOUDINARY_NAME'),
                api_key: env('CLOUDINARY_KEY'),
                api_secret: env('CLOUDINARY_SECRET'),
            }
        }
    //... 
};

.env:

CLOUDINARY_NAME=value
CLOUDINARY_KEY=value
CLOUDINARY_SECRET=value

These are described in the provider’s README:

All the keys that your provide to providerOptions are actually keys from cloudinary:

@vnn8248, @vnn8248 Thank you so much. My problem has been fixed.

I did the same, but it didn’t work on both development and heroku. Strapi still uses local as provider.

./config/plugin.js
module.exports = ({ env }) => ({
  upload: {
    provider: 'cloudinary',
    providerOptions: {
      cloud_name: env('CLOUDINARY_NAME'),
      api_key: env('CLOUDINARY_KEY'),
      api_secret: env('CLOUDINARY_SECRET'),
    },
  },
});

Sorry, i made a typo. It should be plugins.js not plugin.js

2 Likes