File upload failure to Cloudinary using strapi v4

System Information
  • Strapi Version: strapi v4
  • Operating System: ubuntu.20.04.3
  • Database: SQlite
  • Node Version: 6.13.1
  • NPM Version: 8.1.2
  • Yarn Version: 1.22.17

it’s my fists time using strapi with Cloudinary and I’m having issues of images getting uploaded into /public/uploads/ folder rather than uploading to Cloudinary storage service.
as shown below
“url”: “/uploads/thumbnail_myphoto_46806d2062.jpg”

Please let me know if I am doing it the wrong way cause I have I’ve tried all possible solution & failed.

plugins.js

module.exports = ({ env }) => ({

    upload: {
        provider: 'cloudinary',
        providerOptions: {
            cloud_name: env('CLOUDINARY_NAME'),
            api_key: env('CLOUDINARY_KEY'),
            api_secret: env('CLOUDINARY_SECRET'),
          
        },
        actionOptions: {
            upload: {},
            delete: {},
        },
    },

});

package.json

  "devDependencies": {},
  "dependencies": {
    "@strapi/plugin-i18n": "4.0.0",
    "@strapi/plugin-users-permissions": "4.0.0",
    "@strapi/provider-upload-cloudinary": "^4.0.0",
    "@strapi/strapi": "4.0.0",
    "pg": "^8.7.1",
    "pg-connection-string": "^2.5.0",
    "sqlite3": "5.0.2"

middlewares.js

  module.exports = [
  'strapi::errors',
  {
    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,
        },
      },
    },
  },
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::favicon',
  'strapi::public',
];

.env

CLOUDINARY_NAME = xxxxxxxxxxx
CLOUDINARY_KEY = xxxxxxxxxxx
CLOUDINARY_SECRET = xxxxxxxxxxx


I’m getting the same thing. Please Help

Check this out guys, found this solution on the other thread

1 Like

thanks, @devinekadeni for the solution, I finally got this issue sorted by altering my plugins.js file
OLD plugins.js

module.exports = ({ env }) => ({

    upload: {
        provider: 'cloudinary',
        providerOptions: {
            cloud_name: env('CLOUDINARY_NAME'),
            api_key: env('CLOUDINARY_KEY'),
            api_secret: env('CLOUDINARY_SECRET'),
          
        },
        actionOptions: {
            upload: {},
            delete: {},
        },
    },

});

NEW plugins.js

module.exports = ({ env }) => ({

    upload: {
        config:{
        provider: 'cloudinary',
        providerOptions: {
            cloud_name: env('CLOUDINARY_NAME'),
            api_key: env('CLOUDINARY_KEY'),
            api_secret: env('CLOUDINARY_SECRET'),
          
        },
    },
},
});
2 Likes

when i use the above configuration i get these error message:

debug: :no_entry: Server wasn’t able to start properly.
[2022-01-09 17:30:04.239] error: provider.init is not a function

any help please?
Thanks

hello @landolsi, sometimes it can be a node version that is not compatible with strapi v4.
for my case, i used Node: 6.13.1

Hi @filipe256 cloudinary package new installed and it works now.

Thank you.

Hi @landolsi ,

I encounter the same problem as you with “error: provider.init is not a function” when updating the plugin.js file with “config: { … }”

I tried to reinstall the cloudinary package but it still doesn’t work.

What version of node do you currently use on your project ?

Thanks

Hi @NuncEstBibendum ,

I was encountering the same problem and I fixed it by adding cloudinary with the following npm install

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

previously I was using the following npm install

npm i strapi-provider-upload-cloudinary

and that was not working properly for me. Beyond that you need to update the plugins.js and the middleware.js file like mention in the npm documentation

Thanks a lot ! It finally works :smiley: