Generate upload signature (video tutorial)


When using the Cloudinary SDKs for any upload or admin method that requires a signature, the signature is automatically generated and added to the request. If, however, you are making direct calls to the REST API, you need to generate a signature yourself. You can do this using a Cloudinary backend SDK signature generation method. Watch this tutorial to learn how.

Video tutorial

This video is brought to you by Cloudinary's video player - embed your own!

Tutorial contents

This tutorial presents the following topics. Click a timestamp to jump to that part of the video.

Import dependencies for using the Cloudinary Node.js SDK

Jump to this spot in the video  0:09 Get the dependencies to use the Cloudinary Node.js SDK and configure the environment:
Copy to clipboard
const cloudinary = require('cloudinary').v2;

Calculate a timestamp

Jump to this spot in the video  0:14 A timestamp is needed to generate the signature, as signatures are valid for one hour. Calculate a timestamp for the current time in seconds:
Copy to clipboard
var timestamp = Math.round((new Date).getTime()/1000);

Call the sign request method

Jump to this spot in the video  0:19 Call the api_sign_request method to generate the signature. The method requires the parameters to sign, and the API secret:
Copy to clipboard
var signature = cloudinary.utils.api_sign_request({
    timestamp: timestamp,
    eager: 'w_400,h_300,c_pad|w_260,h_200,c_crop',
    public_id: 'sample_image'}, process.env.API_SECRET);

Build a cURL command

Jump to this spot in the video  0:40 Having generated a timestamp and signature for the API call, build a cURL command to call the upload API directly.
Copy to clipboard
var file='';

var curl_command = 'curl -d "file=' + file + 
   '&api_key=323127161127519&eager=w_400,h_300,c_pad|w_260,h_200,c_crop&public_id=sample_image' + 
   '&timestamp=' + timestamp +
   '&signature=' + signature +
   '" -X POST';

Run the code to output the cURL command

Jump to this spot in the video  0:47 Running the code produces a cURL command that can then be used to perform the signed upload by directly calling the upload API.

Enter the cURL command to perform the signed upload

Jump to this spot in the video  1:05 Run the cURL command from the terminal. The returned API response shows a successful signed upload. In reality, the signature generation code would be in a function on your server, into which you would pass the parameters to sign. The function would return the signature and timestamp back to your client where they would be used in a POST request to Cloudinary.

Keep learning

Related topics

If you like this, you might also like...

Upload Programmatically
Use a Cloudinary SDK to upload media assets
Media Library Upload
Drag & drop or select from remote sources to upload
Upload with the CLI
Apply background removal to images on upload


Cloudinary Academy


Check out Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.


✔️ Feedback sent!

Rate this page: