@@ -32,7 +32,7 @@ import CloudConvert from 'cloudconvert';
3232
3333const cloudConvert = new CloudConvert (' api_key' );
3434
35- const job = await cloudConvert .jobs .create ({
35+ let job = await cloudConvert .jobs .create ({
3636 ' tasks' : {
3737 ' import-my-file' : {
3838 ' operation' : ' import/url' ,
@@ -53,6 +53,29 @@ const job = await cloudConvert.jobs.create({
5353```
5454You can use the [ CloudConvert Job Builder] ( https://cloudconvert.com/api/v2/jobs/builder ) to see the available options for the various task types.
5555
56+ ## Downloading Files
57+
58+ CloudConvert can generate public URLs for using ` export/url ` tasks. You can use these URLs to download output files.
59+
60+ ``` js
61+ job = await cloudConvert .jobs .wait (job .id ); // Wait for job completion
62+
63+ const exportTask = job .tasks .filter (task => task .operation === ' export/url' )[0 ];
64+ const file = exportTask .result .files [0 ];
65+
66+ const writeStream = fs .createWriteStream (' ./my-output.ext' );
67+
68+ const response = await axios (file .url , {
69+ responseType: ' stream'
70+ });
71+
72+ response .data .pipe (writeStream);
73+
74+ await new Promise ((resolve , reject ) => {
75+ writeStream .on (' finish' , resolve);
76+ writeStream .on (' error' , reject);
77+ });
78+ ```
5679
5780## Uploading Files
5881
@@ -76,28 +99,6 @@ await cloudConvert.tasks.upload(uploadTask, inputFile);
7699```
77100
78101
79- ## Downloading Files
80-
81- CloudConvert can generate public URLs for using ` export/url ` tasks. You can use these URLs to download output files.
82-
83- ``` js
84- const exportTask = job .tasks .filter (task => task .operation === ' export/url' )[0 ];
85- const file = exportTask .result .files [0 ];
86-
87- const writeStream = fs .createWriteStream (' ./my-output.ext' );
88-
89- const response = await cloudConvert .axios (file .url , {
90- responseType: ' stream'
91- });
92-
93- response .data .pipe (writeStream);
94-
95- await new Promise ((resolve , reject ) => {
96- writeStream .on (' finish' , resolve);
97- writeStream .on (' error' , reject);
98- });
99- ```
100-
101102## Websocket Events
102103
103104The node SDK can subscribe to events of the [ CloudConvert socket.io API] ( https://cloudconvert.com/api/v2/socket#socket ) .
0 commit comments