Signing Uploads with CldUploadWidget
Signing requests is an easy way to provide enhanced security for your file uploads. This helps deter people from making unauthenticated uploads to your cloud.
Configuring Signed Uploads
Setting up CldUploadWidget to sign uploads is as simple as passing an API endpoint as a prop:
However, that API endpoint needs to return a specific shape in order to properly communicate with the CldUploadWidget.
API Endpoint to Sign Requests
When working in Astro, we gain access to a server environment through both somewhat traditional means and serverless functions.
This means, we can use the Cloudinary Node SDK in order to easily sign our requests.
To start off, install the Cloudinary Node SDK with:
In order to sign our requests, we’ll need to use our Cloudinary API Key and Secret, so set additional environment variables:
Then, we want to create a new API endpoint:
Create a new API route file such as src/pages/api/sign-cloudinary-params.ts
and inside add the following:
Whatever path you use will now be the value of signatureEndpoint
for the CldUploadWidget.