You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-34Lines changed: 71 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,14 +63,20 @@ Each request to our secure APIs (e.g., image uploads, eager sprite generation) m
63
63
64
64
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.
65
65
66
+
### Require the Cloudinary library
67
+
68
+
```js
69
+
var cloudinary =require('cloudinary').v2
70
+
```
71
+
66
72
### Overriding the request agent
67
73
To override the request agent pass the agent into any method that makes a
68
74
request and it will be used instead of the normal https agent. e.g
69
-
```js
70
75
76
+
```js
71
77
cloudinary.uploader.upload_stream(
72
-
function(result) { console.log(result); },
73
-
{ agent: myAgent }
78
+
{ agent: myAgent },
79
+
function(error, result) { console.log(result); }
74
80
);
75
81
76
82
```
@@ -81,21 +87,29 @@ Any image uploaded to Cloudinary can be transformed and embedded using powerful
81
87
82
88
The following example generates the url for accessing an uploaded `sample` image while transforming it to fill a 100x150 rectangle:
**See [our documentation](https://cloudinary.com/documentation/node_image_manipulation) for more information about displaying and transforming images in Node.js**.
101
115
@@ -105,65 +119,88 @@ Assuming you have your Cloudinary configuration parameters defined (`cloud_name`
105
119
106
120
The following example uploads a local JPG to the cloud:
**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**.
139
168
140
169
### cloudinary.upload_stream
141
170
142
171
You can use cloudinary.upload_stream to write to the uploader as a stream:
143
172
144
-
var fs = require('fs');
145
-
var stream = cloudinary.uploader.upload_stream(function(result) { console.log(result); });
146
-
var file_reader = fs.createReadStream('my_picture.jpg', {encoding: 'binary'}).on('data', stream.write).on('end', stream.end);
173
+
```js
174
+
var fs =require('fs');
175
+
var stream =cloudinary.uploader.upload_stream(function(error, result) { console.log(result); });
176
+
var file_reader =fs.createReadStream('my_picture.jpg', {encoding:'binary'}).on('data', stream.write).on('end', stream.end);
177
+
```
147
178
148
179
#### Version 1.1 upload_stream change notes
149
180
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:
150
181
151
-
var file_reader = fs.createReadStream('my_picture.jpg').pipe(stream);
182
+
```js
183
+
var file_reader =fs.createReadStream('my_picture.jpg').pipe(stream);
152
184
185
+
```
153
186
if you still need to use event chanining, you can wrap `stream.write` and `stream.end` with wrapper functions
154
187
155
-
var file_reader = fs.createReadStream('my_picture.jpg', {encoding: 'binary'}).
0 commit comments