Securing image downloads from Cloudinary
Uploading images to cloud storage for the purpose of hosting public images is very useful, but what about resources that we want to handle in a more private manner? Cloudinary supports several different types of resource authentication, including the signing of asset URLs.
Getting ready
Let's change our uploaded cover images to be private by default when they are uploaded. We can then make an API endpoint that will automatically sign and redirect to authenticated images that we will only be able to view if we are logged in as an admin user.
How to do it...
Let's perform the following steps to add authentication requirements to view our uploaded Cloudinary images:
- First, we will update our upload functions in
/middleware/cloudinary.js
to default the authentication type of our uploaded images to theauthenticated
type. This will guarantee that they will be inaccessible without a signed URL to access them:
...
upload: function(image, options) {
if (!options...