> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate upload signature (video tutorial)

[githublink]: https://github.com/cloudinary-devs/generate-upload-signature

## Overview

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](client_side_uploading#direct_call_to_the_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!Use the controls to set the playback speed, navigate to chapters of interest and select subtitles in your preferred language.

> **TIP**: :title=View the code

You can find the code from this tutorial in [GitHub][githublink].
## 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
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=0 :sec=09 :player=cld} | Get the dependencies to use the Cloudinary Node.js SDK and configure the environment:

```nodejs
const cloudinary = require('cloudinary').v2;
require('dotenv').config();
```

### Calculate a timestamp
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=0 :sec=14 :player=cld} | A timestamp is needed to generate the signature, as signatures are valid for one hour. Calculate a timestamp for the current time in seconds:

```nodejs
var timestamp = Math.round((new Date).getTime()/1000);
```

### Call the sign request method
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=0 :sec=19 :player=cld} | Call the `api_sign_request` method to generate the signature. The method requires the parameters to sign, and the API secret: 

```nodejs
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
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=0 :sec=40 :player=cld} | Having generated a timestamp and signature for the API call, build a cURL command to call the upload API directly.

```nodejs
var file='https://upload.wikimedia.org/wikipedia/commons/b/b1/VAN_CAT.png';

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 http://api.cloudinary.com/v1_1/carl/image/upload';
```

### Run the code to output the cURL command
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=0 :sec=47 :player=cld} | 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
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=1 :sec=05 :player=cld} | 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

> **READING**:
>
> * Learn more about [uploading assets](upload_images).

> * Learn more about [uploading with a direct call to the REST API](client_side_uploading#direct_call_to_the_api).

#### 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 
  

&nbsp;

&nbsp;Check out the 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.
&nbsp;

