-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,258 +1,103 @@ | ||
[![Build Status](https://travis-ci.org/cloudinary/cloudinary_npm.svg?branch=master)](https://travis-ci.org/cloudinary/cloudinary_npm) | ||
Cloudinary Node SDK | ||
========================= | ||
## About | ||
The Cloudinary Node SDK allows you to quickly and easily integrate your application with Cloudinary. | ||
Effortlessly optimize, transform, upload and manage your cloud's assets. | ||
|
||
Cloudinary | ||
========== | ||
|
||
Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline. | ||
#### Note | ||
This Readme provides basic installation and usage information. | ||
For the complete documentation, see the [Node SDK Guide](https://cloudinary.com/documentation/node_integrations). | ||
|
||
Easily upload images to the cloud. Automatically perform smart image resizing, cropping and conversion without installing any complex software. Integrate Facebook or Twitter profile image extraction in a snap, in any dimension and style to match your website’s graphics requirements. Images are seamlessly delivered through a fast CDN, and much much more. | ||
## Table of Contents | ||
- [Key Features](#key-features) | ||
- [Version Support](#Version-Support) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Setup](#Setup) | ||
- [Transform and Optimize Assets](#Transform-and-Optimize-Assets) | ||
- [Generate Image and HTML Tags](#Generate-Image-and-Video-HTML-Tags) | ||
|
||
Cloudinary offers comprehensive APIs and administration capabilities and is easy to integrate with any web application, existing or new. | ||
|
||
Cloudinary provides URL and HTTP based APIs that can be easily integrated with any Web development framework. | ||
## Key Features | ||
- [Transform](https://cloudinary.com/documentation/node_video_manipulation#video_transformation_examples) and | ||
[optimize](https://cloudinary.com/documentation/node_image_manipulation#image_optimizations) assets. | ||
- Generate [image](https://cloudinary.com/documentation/node_image_manipulation#deliver_and_transform_images) and | ||
[video](https://cloudinary.com/documentation/node_video_manipulation#video_element) tags. | ||
- [Asset Management](https://cloudinary.com/documentation/node_asset_administration). | ||
- [Secure URLs](https://cloudinary.com/documentation/video_manipulation_and_delivery#generating_secure_https_urls_using_sdks). | ||
|
||
For Node.js, Cloudinary provides an extension for simplifying the integration even further. | ||
|
||
## Getting started guide | ||
![](https://res.cloudinary.com/cloudinary/image/upload/see_more_bullet.png) **Take a look at our [Getting started guide for Node.js](https://cloudinary.com/documentation/node_integration#node_js_getting_started_guide)**. | ||
|
||
## Version Support | ||
| SDK Version | node 6-14 | | ||
|---------------|-----------| | ||
| 1.0.0 & up | V | | ||
|
||
## Setup ###################################################################### | ||
|
||
``` npm install cloudinary ``` | ||
|
||
## Try it right away | ||
|
||
Sign up for a [free account](https://cloudinary.com/users/register/free) so you can try out image transformations and seamless image delivery through CDN. | ||
|
||
*Note: Replace `demo` in all the following examples with your Cloudinary's `cloud name`.* | ||
|
||
Accessing an uploaded image with the `sample` public ID through a CDN: | ||
|
||
http://res.cloudinary.com/demo/image/upload/sample.jpg | ||
|
||
![Sample](https://res.cloudinary.com/demo/image/upload/w_0.4/sample.jpg "Sample") | ||
|
||
Generating a 150x100 version of the `sample` image and downloading it through a CDN: | ||
|
||
http://res.cloudinary.com/demo/image/upload/w_150,h_100,c_fill/sample.jpg | ||
|
||
![Sample 150x100](https://res.cloudinary.com/demo/image/upload/w_150,h_100,c_fill/sample.jpg "Sample 150x100") | ||
|
||
Converting to a 150x100 PNG with rounded corners of 20 pixels: | ||
|
||
http://res.cloudinary.com/demo/image/upload/w_150,h_100,c_fill,r_20/sample.png | ||
|
||
![Sample 150x150 Rounded PNG](https://res.cloudinary.com/demo/image/upload/w_150,h_100,c_fill,r_20/sample.png "Sample 150x150 Rounded PNG") | ||
|
||
For plenty more transformation options, see our [image transformations documentation](http://cloudinary.com/documentation/image_transformations). | ||
|
||
Generating a 120x90 thumbnail based on automatic face detection of the Facebook profile picture of Bill Clinton: | ||
|
||
http://res.cloudinary.com/demo/image/facebook/c_thumb,g_face,h_90,w_120/billclinton.jpg | ||
|
||
![Facebook 90x120](https://res.cloudinary.com/demo/image/facebook/c_thumb,g_face,h_90,w_120/billclinton.jpg "Facebook 90x200") | ||
|
||
For more details, see our documentation for embedding [Facebook](https://cloudinary.com/documentation/facebook_profile_pictures) and [Twitter](https://cloudinary.com/documentation/twitter_profile_pictures) profile pictures. | ||
|
||
|
||
## Usage | ||
|
||
### Configuration | ||
|
||
Each request for building a URL of a remote cloud resource must have the `cloud_name` parameter set. | ||
Each request to our secure APIs (e.g., image uploads, eager sprite generation) must have the `api_key` and `api_secret` parameters set. See [API, URLs and access identifiers](https://cloudinary.com/documentation/solution_overview#account_and_api_setup) for more details. | ||
|
||
Setting the `cloud_name`, `api_key` and `api_secret` parameters can be done either directly in each call to a Cloudinary method, by calling the cloudinary.config(), or by using the CLOUDINARY_URL environment variable. | ||
|
||
### Require the Cloudinary library | ||
|
||
```js | ||
var cloudinary = require('cloudinary').v2 | ||
``` | ||
|
||
### Overriding the request agent | ||
To override the request agent pass the agent into any method that makes a | ||
request and it will be used instead of the normal https agent. e.g | ||
|
||
```js | ||
cloudinary.uploader.upload_stream( | ||
{ agent: myAgent }, | ||
function(error, result) { console.log(result); } | ||
); | ||
|
||
## Installation | ||
```bash | ||
npm install cloudinary | ||
``` | ||
|
||
### Embedding and transforming images | ||
|
||
Any image uploaded to Cloudinary can be transformed and embedded using powerful view helper methods: | ||
|
||
The following example generates the url for accessing an uploaded `sample` image while transforming it to fill a 100x150 rectangle: | ||
|
||
# Usage | ||
### Setup | ||
```js | ||
cloudinary.url("sample.jpg", {width: 100, height: 150, crop: "fill"}) | ||
// Require the Cloudinary library | ||
const cloudinary = require('cloudinary').v2 | ||
``` | ||
|
||
Another example, emedding a smaller version of an uploaded image while generating a 90x90 face detection based thumbnail: | ||
### Transform and Optimize Assets | ||
- [See full documentation](https://cloudinary.com/documentation/node_image_manipulation). | ||
|
||
```js | ||
cloudinary.url("woman.jpg", {width: 90, height: 90, crop: "thumb", gravity: "face"}); | ||
cloudinary.url("sample.jpg", {width: 100, height: 150, crop: "fill", fetch_format: "auto"}) | ||
``` | ||
|
||
You can provide either a Facebook name or a numeric ID of a Facebook profile or a fan page. | ||
|
||
Embedding a Facebook profile to match your graphic design is very simple: | ||
|
||
```js | ||
cloudinary.url("billclinton.jpg", {width: 90, height: 130, type: "facebook", crop: "fill", gravity: "north_west"}); | ||
``` | ||
|
||
Same goes for Twitter: | ||
|
||
```js | ||
cloudinary.url("billclinton.jpg", {type: "twitter_name"}); | ||
``` | ||
|
||
![](https://res.cloudinary.com/cloudinary/image/upload/see_more_bullet.png) **See [our documentation](https://cloudinary.com/documentation/node_image_manipulation) for more information about displaying and transforming images in Node.js**. | ||
|
||
### Upload | ||
|
||
Assuming you have your Cloudinary configuration parameters defined (`cloud_name`, `api_key`, `api_secret`), uploading to Cloudinary is very simple. | ||
|
||
The following example uploads a local JPG to the cloud: | ||
|
||
- [See full documentation](https://cloudinary.com/documentation/node_image_and_video_upload). | ||
- [Learn more about configuring your uploads with upload presets](https://cloudinary.com/documentation/upload_presets). | ||
```js | ||
var cloudinary = require('cloudinary').v2; | ||
cloudinary.uploader.upload("my_picture.jpg", function(error, result) { console.log(result) }); | ||
cloudinary.v2.uploader.upload("/home/my_image.jpg", {upload_preset: "my_preset"}, (error, result)=>{ | ||
console.log(result, error); | ||
}); | ||
``` | ||
|
||
Below is an example of an upload's result: | ||
|
||
```json | ||
{ | ||
"public_id": "4srvcynxrf5j87niqcx6w", | ||
"version": 1340625837, | ||
"signature": "01234567890abcdef01234567890abcdef012345", | ||
"width": 200, | ||
"height": 200, | ||
"format": "jpg", | ||
"resource_type": "image", | ||
"url": "http://res.cloudinary.com/demo/image/upload/v1340625837/4srvcynxrf5j87niqcx6w.jpg", | ||
"secure_url": "https://res.cloudinary.com/demo/image/upload/v1340625837/4srvcynxrf5j87niqcx6w.jpg" | ||
} | ||
``` | ||
|
||
The uploaded image is assigned a randomly generated public ID. The image is immediately available for download through a CDN: | ||
|
||
```js | ||
cloudinary.url("abcfrmo8zul1mafopawefg.jpg"); | ||
|
||
// http://res.cloudinary.com/demo/image/upload/abcfrmo8zul1mafopawefg.jpg | ||
``` | ||
You can also specify your own public ID: | ||
|
||
```js | ||
cloudinary.uploader.upload( | ||
"http://www.example.com/image.jpg", | ||
{public_id: 'sample_remote'}, | ||
function(error, result) { | ||
console.log(result) | ||
} | ||
); | ||
|
||
cloudinary.url("sample_remote.jpg") | ||
|
||
// http://res.cloudinary.com/demo/image/upload/sample_remote.jpg | ||
|
||
``` | ||
|
||
![](https://res.cloudinary.com/cloudinary/image/upload/see_more_bullet.png) **See [our documentation](https://cloudinary.com/documentation/node_image_upload) for plenty more options of uploading to the cloud from your Node.js code or directly from the browser**. | ||
|
||
### cloudinary.upload_stream | ||
|
||
You can use cloudinary.upload_stream to write to the uploader as a stream: | ||
|
||
```js | ||
var fs = require('fs'); | ||
var stream = cloudinary.uploader.upload_stream(function(error, result) { console.log(result); }); | ||
var file_reader = fs.createReadStream('my_picture.jpg', {encoding: 'binary'}).on('data', stream.write).on('end', stream.end); | ||
``` | ||
|
||
#### Version 1.1 upload_stream change notes | ||
The `upload_stream` method was modified to return a `Transform` stream object, we advise to change the `on('data')` and `on('end')` to pipe API: | ||
|
||
```js | ||
var file_reader = fs.createReadStream('my_picture.jpg').pipe(stream); | ||
|
||
``` | ||
if you still need to use event chanining, you can wrap `stream.write` and `stream.end` with wrapper functions | ||
|
||
```js | ||
var file_reader = fs.createReadStream('my_picture.jpg', {encoding: 'binary'}) | ||
.on('data', function(data){stream.write(data)}) | ||
.on('end', function(){stream.end()}); | ||
``` | ||
### cloudinary.image | ||
|
||
Returns an html image tag pointing to Cloudinary. | ||
|
||
Usage: | ||
|
||
### Large/Chunked Upload | ||
- [See full documentation](https://cloudinary.com/documentation/node_image_and_video_upload#node_js_video_upload). | ||
```js | ||
cloudinary.image("sample", {format: "png", width: 100, height: 100, crop: "fill"}) | ||
|
||
// <img src='http://res.cloudinary.com/demo/image/upload/c_fill,h_100,w_100/sample.png' height='100' width='100'/> | ||
cloudinary.v2.uploader.upload_large(LARGE_RAW_FILE, { | ||
chunk_size: 7000000 | ||
}, (error, result) => {console.log(error)}); | ||
``` | ||
### Security options | ||
- [See full documentation](https://cloudinary.com/documentation/solution_overview#security). | ||
|
||
### Typescript | ||
## Contributions | ||
- Ensure tests run locally (add test command) | ||
- Open a PR and ensure Travis tests pass | ||
|
||
🎉New 🎉TypeScript support was just added. Check out the [declaration file](https://github.com/cloudinary/cloudinary_npm/blob/master/types/index.d.ts). | ||
|
||
### Samples | ||
## Get Help | ||
If you run into an issue or have a question, you can either: | ||
- Issues related to the SDK: [Open a Github issue](https://github.com/cloudinary/cloudinary_npm/issues). | ||
- Issues related to your account: [Open a support ticket](https://cloudinary.com/contact) | ||
|
||
You can find our simple and ready-to-use samples projects, along with documentation in the [samples folder](https://github.com/cloudinary/cloudinary_npm/tree/master/samples). | ||
Please consult with the [README file](https://github.com/cloudinary/cloudinary_npm/blob/master/samples/readme.md), for usage and explanations. | ||
|
||
## About Cloudinary | ||
Cloudinary is a powerful media API for websites and mobile apps alike, Cloudinary enables developers to efficiently manage, transform, optimize, and deliver images and videos through multiple CDNs. Ultimately, viewers enjoy responsive and personalized visual-media experiences—irrespective of the viewing device. | ||
|
||
## Additional resources ########################################################## | ||
|
||
Additional resources are available at: | ||
## Additional Resources | ||
- [Cloudinary Transformation and REST API References](https://cloudinary.com/documentation/cloudinary_references): Comprehensive references, including syntax and examples for all SDKs. | ||
- [MediaJams.dev](https://mediajams.dev/): Bite-size use-case tutorials written by and for Cloudinary Developers | ||
- [DevJams](https://www.youtube.com/playlist?list=PL8dVGjLA2oMr09amgERARsZyrOz_sPvqw): Cloudinary developer podcasts on YouTube. | ||
- [Cloudinary Academy](https://training.cloudinary.com/): Free self-paced courses, instructor-led virtual courses, and on-site courses. | ||
- [Code Explorers and Feature Demos](https://cloudinary.com/documentation/code_explorers_demos_index): A one-stop shop for all code explorers, Postman collections, and feature demos found in the docs. | ||
- [Cloudinary Roadmap](https://cloudinary.com/roadmap): Your chance to follow, vote, or suggest what Cloudinary should develop next. | ||
- [Cloudinary Facebook Community](https://www.facebook.com/groups/CloudinaryCommunity): Learn from and offer help to other Cloudinary developers. | ||
- [Cloudinary Account Registration](https://cloudinary.com/users/register/free): Free Cloudinary account registration. | ||
- [Cloudinary Website](https://cloudinary.com): Learn about Cloudinary's products, partners, customers, pricing, and more. | ||
|
||
* [Website](https://cloudinary.com) | ||
* [Interactive demo](https://demo.cloudinary.com/default) | ||
* [Documentation](https://cloudinary.com/documentation) | ||
* [Knowledge Base](https://support.cloudinary.com/hc/en-us) | ||
* [Documentation for Node.js integration](https://cloudinary.com/documentation/node_integration) | ||
* [Node.js image upload documentation](https://cloudinary.com/documentation/node_image_upload) | ||
* [Node.js image manipulation documentation](https://cloudinary.com/documentation/node_image_manipulation) | ||
* [Image transformations documentation](https://cloudinary.com/documentation/image_transformations) | ||
|
||
## Run test | ||
|
||
``` | ||
npm run test | ||
``` | ||
|
||
## Node support | ||
This SDK requires node >= 8. | ||
|
||
## Support | ||
|
||
You can [open an issue through GitHub](https://github.com/cloudinary/cloudinary_npm/issues). | ||
|
||
Contact us [https://cloudinary.com/contact](https://cloudinary.com/contact) | ||
|
||
Stay tuned for updates, tips and tutorials: [Blog](https://cloudinary.com/blog), [Twitter](https://twitter.com/cloudinary), [Facebook](https://www.facebook.com/Cloudinary). | ||
|
||
## Join the Community ########################################################## | ||
|
||
Impact the product, hear updates, test drive new features and more! Join [here](https://www.facebook.com/groups/CloudinaryCommunity). | ||
|
||
|
||
## License ####################################################################### | ||
|
||
## Licence | ||
Released under the MIT license. | ||
|
||
Test resources include the video [Cloud Book Study](https://vimeo.com/27172301) | ||
which was created by [Heidi Neilson](https://vimeo.com/heidineilson) | ||
and is distributed under the Creative commons - attribution license (CC BY 3.0) |