Special character within metadata in signed api upload
Hello guys,
I've built an application to upload files through the signed api upload.
The upload works perfect. Now I would like to extend the upload with metadata. I've created different structured metadata fields, e.g. sku, year and product name.
Using sku and year works smooth. But if I use the field product_name which contains a special character, the signing of the request fails
This is my body:
&signature=XXX ×tamp=1673016560000 &metadata=sku=00002620|year=2020|product_name=Colère Folle Blanche Vin de France Vices & Vertus &public_id=00002620 &upload_preset=test_preset &api_key=XXX&file=https://XXX
and this is the error message:
HTTP status: 401 (Unauthorized), Response Content: {"error":{"message":"Invalid Signature c8c8b1f3f1ac8f492de1bac138419f7e1c0eb938. String to sign - 'metadata=sku=00002620|year=2020|product_name=Col?re Folle Blanche Vin de France Vices&pu...
As you can see, within the product_name there is a special character and this cause the error with the signing. Any idea how to deal with this?
Cheers
Ramin
Best Answer
-
Hello @Ramin
Thank you for including the details of the request body and the response.
I attempted to replicate the problem on my end. After adding the `product_name` structured metadata field I used Cloudinary Node.js SDK to perform a signed upload for an asset while assigning the metadata value with the special character.
require('dotenv').config()
const cloudinary = require('cloudinary').v2
cloudinary.uploader.upload('https://picsum.photos/200', {
metadata:'product_name=Colère Folle Blanche Vin de France Vices & Vertus',
})
.then(console.log)
.catch(console.error);
The upload succeeds and the correct value is assigned to the metadata field on the asset.
Then I noticed that the request to Cloudinary is performed via the `Synesty-Studio` (as indicated by the data included with the request):
User Agent: Synesty-Studio (https://apps.synesty.com; Flow: 3c73e40a-8dad-11ed-aa46-901b0ea49fee RunID: 1)
Most likely, the problem is caused due to the metadata value with the special character that is used to generate signature on your end ( `Colère Folle Blanche Vin de France Vices & Vertus` ) does not match the one Cloudinary receives and re-calculates the signature on ( `Col?re Folle Blanche Vin de France Vices` ). It appears the value gets modified somewhere in the Synesty-Studio > HTTP request > Cloudinary chain.
May I ask you to review and share more details on how the Cloudinary Upload API request is configured with Synesty-Studio? Is any Cloudinary SDK used to make the API call or is it configured as a "pure" HTTP request?
At this point, I speculate that the change may occur in Synesty-Studio chain (as the value with the special character is converted from UTF8 to ASCII encoding, for example, before the HTTP request to Cloudinary API is made).
While reviewing the setup in Synesty-Studio (in case it is configured as a "pure" HTTP request) - you may also find Cloudinary's Postman Collections (https://cloudinary.com/documentation/using_cloudinary_postman_collections) to be a useful resource. Configuration and pre-request script for the `Upload API > Upload > Upload File - Signed` request can serve as a working example.
You can also use the aforementioned request from Cloudinary's Postman collection for additional testing on your end to confirm the origin of the issue.
Best regards, Andrew
0