As you know, if you deploy your Strapi server to Heroku, the cache will continuously clear after 24hrs. With that being said, if you have any images on your project, they'll break within a day. Upsetting, I know.
There's a fairly simple solution!
- Create a Cloudinary account
- Connect it to Strapi
Under the assumption that you've already created a Cloudinary account, go ahead and install the strapi-provider-upload-cloudinary plugin to your Strapi server:
yarn add strapi-provider-upload-cloudinary
From here, you need to give Strapi access to your account, so we'll be setting up a config file.
First, we need to locate the "extensions" folder. Now, we need to add a couple folders, from "extensions" add a new folder by the name of "upload". Now upload needs a child folder by the name of "config". Lastly, you can add a settings.json file inside of your config folder. Your path should look like this: extensions > upload > config > settings.json.
Now that that's set up, we can get to the last step!
The contents of this file are pretty straightforward. If you navigate back to your Cloudinary dashboard you will find your cloud name, API key, and your API secret.
Go ahead and insert them in this format:
{
"provider": "cloudinary",
"providerOptions": {
"cloud_name": "your_cloud_name",
"api_key": "your_api_key",
"api_secret": "your_api_secret"
}
}
And that's it! Yeah, I thought it was going to be harder than that as well. If you navigate back to your Strapi server and add an image somewhere, then go back to your Cloudinary media you'll see your image is now being stored! It'll take Strapi a bit to understand what's going on so if you can't query your images right away, don't fret, they'll be available soon.
Thank you for taking the time to read this over! Happy hacking ~(^-^)~