1

UPDATE: I installed Strapi version 3.6.3 and it works well

Strapi - Clouinary connection do not work for me. So I'm uploading pictures to Stapi, but they don't appear in Clouinary.

In config folder I created file plugins.js with following content:

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

I have installed npm i strapi-provider-upload-cloudinary

then changed file .env to

PORT=1337
CLOUDINARY_NAME="***"
CLOUDINARY_KEY="***"
CLOUDINARY_SECRET="***"```

Actually automatically following code added automatically:
```JWT_SECRET=*********
API_TOKEN_SALT=*********
JWT_SECRET=*********

What could be a problem? should CLOUDINARY_SECRET be in "quotes"? or in 'quotes' or without quotes?

Terminal output after adding image is following:

http://localhost:1337

[2021-12-07 02:10:14.702] http: POST /upload (261 ms) 200
[2021-12-07 02:10:14.744] http: GET /upload/files?sort=updatedAt:DESC&page=1&pageSize=10 (24 ms) 200
[2021-12-07 02:10:14.758] http: GET /uploads/thumbnail_Screenshot_2021_11_26_130226_11a95e81ea.png?width=1504&height=1258 (4 ms) 200

All permissions seems to be set...

Also created extentions/upload/config/setting.json with the following content:

    "provider": "cloudinary",
    "providerOptions": {     "cloud_name":"devert0mt",
      "api_key": "***",               
      "api_secret":"***"
    }
  }{
    "provider": "cloudinary",
    "providerOptions": {     "cloud_name":"devert0mt",
      "api_key": "***",               
      "api_secret":"***"
    }
  }```
2
  • 2
    You shouldn't post your Cloudinary API Secret publicly. I recommend changing your current access keys ASAP. This can be done on the security tab on your Cloudinary dashboard. Commented Dec 7, 2021 at 9:30
  • I believe the keys should be without quotes. And I second what @RoeeBen-Ari said previously: never post your secret keys publicly. There's a reason they're called secret keys... Obtain new keys from Cloudinary and remove the ones you posted ASAP. Commented Dec 14, 2021 at 7:51

2 Answers 2

3

If you want to use the latest version of Strapi, v.4 and above, you need to change strapi provider package to this one:

npm install @strapi/provider-upload-cloudinary --save

Then, you need to update your plugins.js file in config/plugins.js to the following ( Be aware that it has a slightly different structure than the previous package - everything is placed in config object, instead of upload like it was on a previous version):

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

Also, if you are having issues with properly rendering your images on your Strapi dashboard you can update middlewares.js in config/middlewares.js:

Instead of 'strapi::security' in module.exports, paste this:

// ...
  {
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'connect-src': ["'self'", 'https:'],
          'img-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
          'media-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
// ...
Sign up to request clarification or add additional context in comments.

5 Comments

I have the same problem... But my config is up to date with the latest packages... Still doesnt work tho... Does it have something to do with working locally or in production?
Never mind, i had "plugin.js" instead of "plugins.js" as a foldername! Its works now.. stupid mistake... 🤷‍♂️
wow @mikeyfe6 you're a lifesaveer, I have been trying to figure out why the images only uploaded to local. changing the file name to plugins.js worked!
You're welcome(, i think....) 🥲 @GameBoy
I have the same error but nothing works for me. My file name is plugins.js. Please help me!!
2

If you do all the configuration in latest version but it won't work, maybe this is the solution. I check the name of file is config/plugins.js not config/plugin.js. This file must have s. LOL

1 Comment

Another one saved by a single 's'! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.