I am trying to apply a named transformation to a private asset but getting a 401.
Context
Settings -> Security -> Strict Transformations -> enabled
I created a named transformation -> t_thumbnail.
This transformation is allowed to be applied in strict transformations
I uploaded a photo with the following code
const uploadImage = async (imagePath) => {
const options = {
use_filename: true,
unique_filename: false,
overwrite: true,
type: 'private'
};
try {
const result = await cloudinary.uploader.upload(imagePath, options);
return result.public_id;
} catch (error) {
console.error(error);
}
};
When I try to apply the transformation, I am getting a 401
I tried calling the API
const createThumbnailPhoto = async (cloudinaryPhotoId) => {
const THUMBNAIL_NAMED_TRANSFORMATION = 'thumbnail';
const result = await cloudinary.image(cloudinaryPhotoId, {
transformation: [THUMBNAIL_NAMED_TRANSFORMATION]
})
return result
}
or adding the /t_thumbnail/
in the image url
I read the documentation, and it should be possible to achieve this, but I am stuck.
Based on the URL you shared that doesn't work:
We see that the version component (v1689960195
) is not in the right place. The version component is optional, but if included, needs to come right before the public_id
(sample-2). In your example, it is set before the transformation component (t_thumbnail
) which then leads to the error.
Please refer to this section of the Cloudinary Documentation for the structure of URLs: https://cloudinary.com/documentation/image_transformations#transformation_url_structure
If we move the version component to the correct place then the URL will work:
Since the transformed/derived version is generated based on the valid request from above, your original URL (with the version in the wrong place) will also work.
To resolve the issue, you will want to check your code that generates the URL or if you're modifying the URL returned by Cloudinary and inserting the t_thumbnail
named transformation in the middle of it then you will want to make sure you are adding it before the version component and not after.
Since you're using the Cloudinary NodeJS SDK, you can use the built-in methods to generate the URL to your images without needing to do this in your own code. Please see this section with details of the methods and examples: https://cloudinary.com/documentation/node_image_manipulation#direct_url_building