Upload File to Cloudinary Using Admin Api

Overview

Cloudinary's Node.js SDK provides uncomplicated, even so comprehensive prototype and video upload, transformation, optimization, and delivery capabilities that yous can implement using lawmaking that integrates seamlessly with your existing Node.js application.

In this guide you'll learn how to become started with the Node.js SDK, but if you lot are not familiar with Cloudinary, we propose starting with the Developer get started guide for a loftier-level overview of integrating Cloudinary into your code, and an introduction to the main concepts.

You may also find our Glossary helpful to understand Cloudinary-specific terminology.

This guide relates to the latest released version of the Cloudinary Node.js library.

For details on all new features and fixes from previous versions, see the CHANGELOG.

  • Overview
  • Quick instance: Transformations
  • Quick example: File upload
  • Node.js SDK features
  • Installation and setup
  • Configuration
  • Node.js capitalization and information blazon guidelines
  • Sample projects

Quick example: Transformations

Take a look at the post-obit transformation code and the image information technology delivers:

Node.js (cloudinary 1.x):

Copy to clipboard

cloudinary.image(                  "                  front_face.png                  "                , {secure:                truthful,                transformation: [   {width:                150,                height:                150,                gravity:                                  "                  face                  "                ,                crop:                                  "                  thumb                  "                },   {radius:                20},   {result:                                  "                  sepia                  "                },   {overlay:                                  "                  cloudinary_icon_blue                  "                ,                gravity:                                  "                  south_east                  "                ,                ten:                5,                y:                v,                width:                fifty,                opacity:                60,                effect:                                  "                  brightness:200                  "                },   {bending:                10}   ]})

sample transformation

This relatively simple code performs all of the following on the original front_face.jpg image before delivering information technology:

  • Crop to a 150x150 thumbnail using face-detection gravity to automatically determine the location for the ingather
  • Round the corners with a 20 pixel radius
  • Utilize a sepia event
  • Overlay the Cloudinary logo on the southeast corner of the image (with a slight offset). The logo is scaled down to a 50 pixel width, with increased brightness and partial transparency (opacity = 60%)
  • Rotate the resulting paradigm (including the overlay) by x degrees
  • Convert and deliver the prototype in PNG format (the originally uploaded epitome was a JPG)

And hither's the URL that would be included in the image tag that's automatically generated from the above lawmaking:

In a similar fashion, you tin can transform a video.

Quick example: File upload

The post-obit Node.js code uploads the dog.mp4 video to the specified account sub-folder using the public_id, my_dog. The video will overwrite the existing my_dog video if it exists. When the video upload is complete, the specified notification URL volition receive details nearly the uploaded media asset.

Copy to clipboard

cloudinary.v2.uploader.upload(                "                canis familiaris.mp4                "              ,    {resource_type:                              "                video                "              ,              public_id:                              "                myfolder/mysubfolder/my_dog                "              ,              overwrite:              true,              notification_url:                              "                https://mysite.case.com/notify_endpoint                "              },              office(error, effect) {console.log(result, mistake)});

Node.js SDK features

  • Build URLs for paradigm and video transformation
  • Node.js helper methods for embedding and transforming images
  • API wrappers: file upload, administration, sprite generation and more
  • Server-side file upload + directly unsigned file upload from the browser using the jQuery plugin
  • TypeScript back up. View the TypeScript declaration file.

Installation and setup

Cloudinary's Node.js integration library is available every bit an open up-source NPM. To install the Cloudinary NPM, run:

Include Cloudinary'southward Node.js classes in your code:

Copy to clipboard

              var              cloudinary = require(                '                cloudinary                '              );

The Node.js SDK upload and admin method syntax examples shown throughout this documentation apply the v2 signature. To avoid confusion, all code examples are shown in the format cloudinary.v2....

In your own code, information technology is recommended to include v2 of the Node.js classes as follows:

Re-create to clipboard

                var                cloudinary = require(                  '                  cloudinary                  '                ).v2;

Alternatively, from within a module, y'all can use an ES6 import statement:

Re-create to clipboard

                import                { v2 every bit cloudinary } from                                  '                  cloudinary                  '                              

Following either of these, your upload and Admin API calls should omit the .v2 shown in the code examples of this guide.
For example, a simple image upload:

Copy to clipboard

cloudinary.uploader.upload(                  "                  my_image.jpg                  "                ,                function(error, result) {console.log(result, error)});

Configuration

To utilise the Cloudinary Node.js library, you have to configure at to the lowest degree your cloud_name. Your api_key and api_secret are besides needed for secure API calls to Cloudinary (e.g., image and video uploads). You tin notice your business relationship-specific configuration credentials in the Dashboard page of the account console.

In improver to the required configuration parameters, y'all tin ascertain a number of optional configuration parameters if relevant.

Setting the configuration parameters can be done globally, using either an environment variable or the config method, or programmatically in each telephone call to a Cloudinary method. Parameters ready in a call to a Cloudinary method override globally gear up parameters.

For backward compatibility reasons, the default value of the optional secure configuration parameter is false. However, for well-nigh modern applications, it's recommended to configure the secure parameter to truthful to ensure that your transformation URLs are always generated as HTTPS.

Setting the CLOUDINARY_URL environment variable

You tin configure the required cloud_name, api_key, and api_secret by defining the CLOUDINARY_URL environment variable. The CLOUDINARY_URL value is available in the Dashboard folio of the business relationship console. When using Cloudinary through a PaaS add-on (eastward.g., Heroku or AppFog), this environs variable is automatically divers in your deployment environment. For example:

Copy to clipboard

CLOUDINARY_URL=cloudinary://my_key:my_secret@my_cloud_name

Prepare boosted parameters, for example upload_prefix and cname, to the environment variable:

Copy to clipboard

CLOUDINARY_URL=cloudinary://my_key:my_secret@my_cloud_name?cname=mydomain.com&upload_prefix=myprefix.com

Setting configuration parameters globally

Here'due south an case of setting configuration parameters globally in your Node application:

Copy to clipboard

cloudinary.config({              cloud_name:                              '                sample                '              ,              api_key:                              '                874837483274837                '              ,              api_secret:                              '                a676b67565c6767a6767d6767f676fe1                '              ,              secure:              truthful              });

Node.js capitalization and information type guidelines

When using the Node.js SDK, keep these guidelines in listen:

  • Parameter names: snake_case. For example: public_id
  • Classes: PascalCase. For example: PreloadedFile
  • Methods: snake_case. For example: image_upload_tag
  • Laissez passer parameter information equally: Object

Sample projects

For boosted useful lawmaking samples and to larn how to integrate Cloudinary with your Node.js applications, take a await at our Sample Projects.

  • Basic Node.js sample: Uploading local and remote images to Cloudinary and generating various transformation URLs.
  • Node.js Photo Album: A fully working web awarding that allows you to upload photos, maintain a database with references, list images with their metadata, and display them using diverse cloud-based transformations. Paradigm uploading is performed both from the server side and direct from the browser using a jQuery plugin.
  • Learn more about uploading images and videos using the Node.js SDK.
  • Meet examples of powerful prototype and video transformations using Node.js code, and meet our image transformations and video transformation docs.
  • Check out Cloudinary's nugget assistants capabilities, for case, renaming and deleting assets, adding tags and metadata to assets, and searching for assets.
  • Stay tuned for updates, tips and tutorials in Product Updates and Blog Posts.

sandersater1946.blogspot.com

Source: https://cloudinary.com/documentation/node_integration

0 Response to "Upload File to Cloudinary Using Admin Api"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel