@@ -16,7 +16,7 @@ By default, API Key, Sandbox and Webhook Signing Secret are being read from `app
1616``` properties
1717CLOUDCONVERT_API_KEY =<api-key>
1818CLOUDCONVERT_SANDBOX =<true|false>
19- CLOUDCONVERT_WEBHOOK_SIGNING_SECRET =<api-url >
19+ CLOUDCONVERT_WEBHOOK_SIGNING_SECRET =<secret >
2020```
2121It is also possible to provide configuration above using environment variables, custom properties file, system properties and string variables.
2222For all options, ` CLOUDCONVERT_API_KEY ` , ` CLOUDCONVERT_SANDBOX ` and ` CLOUDCONVERT_WEBHOOK_SIGNING_SECRET ` variable names should be used.
@@ -33,7 +33,7 @@ new CloudConvertClient(new EnvironmentVariableSettingsProvider());
3333new CloudConvertClient (new PropertyFileSettingsProvider (" custom.properties" ));
3434
3535// Using configuration from string variables
36- new CloudConvertClient (new StringSettingsProvider (" api-url" , " webhook-signing-secret" ));
36+ new CloudConvertClient (new StringSettingsProvider (" api-url" , " webhook-signing-secret" , false ));
3737
3838// Using configuration from system properties
3939new CloudConvertClient (new SystemPropertySettingsProvider ());
@@ -51,7 +51,7 @@ new AsyncCloudConvertClient(new EnvironmentVariableSettingsProvider());
5151new AsyncCloudConvertClient (new PropertyFileSettingsProvider (" custom.properties" ));
5252
5353// Using configuration from string variables
54- new AsyncCloudConvertClient (new StringSettingsProvider (" api-url" , " webhook-signing-secret" ));
54+ new AsyncCloudConvertClient (new StringSettingsProvider (" api-url" , " webhook-signing-secret" , false ));
5555
5656// Using configuration from system properties
5757new AsyncCloudConvertClient (new SystemPropertySettingsProvider ());
@@ -68,7 +68,10 @@ final CloudConvertClient cloudConvertClient = new CloudConvertClient();
6868final JobResponse createJobResponse = cloudConvertClient. jobs(). create(
6969 ImmutableMap . of(
7070 " import-my-file" , new UrlImportRequest (). setUrl(" import-url" ),
71- " convert-my-file" , new ConvertFilesTaskRequest (). setInput(" import-my-file" ). set(" width" , 100 ). set(" height" , 100 ),
71+ " convert-my-file" , new ConvertFilesTaskRequest ()
72+ .setInput(" import-my-file" )
73+ .set(" width" , 100 )
74+ .set(" height" , 100 ),
7275 " export-my-file" , new UrlExportRequest (). setInput(" convert-my-file" )
7376 )
7477). getBody();
@@ -92,7 +95,10 @@ final AsyncCloudConvertClient asyncCloudConvertClient = new AsyncCloudConvertCli
9295final JobResponse createJobResponse = asyncCloudConvertClient. jobs(). create(
9396 ImmutableMap . of(
9497 " import-my-file" , new UrlImportRequest (). setUrl(" import-url" ),
95- " convert-my-file" , new ConvertFilesTaskRequest (). setInput(" import-my-file" ). set(" width" , 100 ). set(" height" , 100 ),
98+ " convert-my-file" , new ConvertFilesTaskRequest ()
99+ .setInput(" import-my-file" )
100+ .set(" width" , 100 )
101+ .set(" height" , 100 ),
96102 " export-my-file" , new UrlExportRequest (). setInput(" convert-my-file" )
97103 )
98104). get(). getBody();
@@ -112,44 +118,36 @@ CloudConvert can generate public URLs using `export/url` tasks. You can use thes
112118
113119###### Default (synchronous) client
114120``` java
115- // Create a client
116- final CloudConvertClient cloudConvertClient = new CloudConvertClient ();
117-
118- // Create an export/url task
119- final TaskResponse exportUrlTaskResponse = cloudConvertClient. exportUsing(). url(new UrlExportRequest ()). getBody();
120-
121- // Get an export/url task id
122- final String exportUrlTaskId = exportUrlTaskResponse. getId();
123-
124121// Wait for an export/url task to be finished
125122final TaskResponse waitUrlExportTaskResponse = cloudConvertClient. tasks(). wait(exportUrlTaskId). getBody();
126123
127- // Get a url of export/url task
124+ // Get url and filename of export/url task
128125final String exportUrl = waitUrlExportTaskResponse. getResult(). getFiles(). get(0 ). get(" url" );
126+ final String filename = waitUrlExportTaskResponse. getResult(). getFiles(). get(0 ). get(" filename" );
129127
130128// Get file as input stream using url of export/url task
131129final InputStream inputStream = cloudConvertClient. files(). download(exportUrl). getBody();
130+
131+ // Save to local file
132+ OutputStream outputStream = new FileOutputStream (new File (filename));
133+ IOUtils . copy(inputStream, outputStream);
132134```
133135
134136###### Asynchronous client
135137``` java
136- // Create a client
137- final AsyncCloudConvertClient asyncCloudConvertClient = new AsyncCloudConvertClient ();
138-
139- // Create an export/url task
140- final TaskResponse exportUrlTaskResponse = asyncCloudConvertClient. exportUsing(). url(new UrlExportRequest ()). get(). getBody();
141-
142- // Get an export/url task id
143- final String exportUrlTaskId = exportUrlTaskResponse. getId();
144-
145138// Wait for an export/url task to be finished
146139final TaskResponse waitUrlExportTaskResponse = asyncCloudConvertClient. tasks(). wait(exportUrlTaskId). get(). getBody();
147140
148141// Get a url of export/url task
149142final String exportUrl = waitUrlExportTaskResponse. getResult(). getFiles(). get(0 ). get(" url" );
143+ final String filename = waitUrlExportTaskResponse. getResult(). getFiles(). get(0 ). get(" filename" );
150144
151145// Get file as input stream using url of export/url task
152146final InputStream inputStream = asyncCloudConvertClient. files(). download(exportUrl). get(). getBody();
147+
148+ // Save to local file
149+ OutputStream outputStream = new FileOutputStream (new File (filename));
150+ IOUtils . copy(inputStream, outputStream);
153151```
154152
155153## Uploading Files
@@ -189,7 +187,6 @@ final TaskResponse waitUploadImportTaskResponse = asyncCloudConvertClient.tasks(
189187## Signing Webhook
190188The node SDK allows to verify webhook requests received from CloudConvert.
191189
192- ###### Default (synchronous) client
193190``` java
194191// Create a client
195192final CloudConvertClient cloudConvertClient = new CloudConvertClient ();
@@ -200,31 +197,10 @@ final String payload = "payload";
200197// The value of the "CloudConvert-Signature" header.
201198final String signature = " signature" ;
202199
203- // You can find it in your webhook settings.
204- final String secret = " secret" ;
205-
206200// Returns true if signature is valid, and false if signature is invalid
207201final boolean isValid = cloudConvertClient. webhooks(). verify(payload, signature);
208202```
209203
210- ###### Asynchronous client
211- ``` java
212- // Create a client
213- final AsyncCloudConvertClient asyncCloudConvertClient = new AsyncCloudConvertClient ();
214-
215- // The JSON payload from the raw request body.
216- final String payload = " payload" ;
217-
218- // The value of the "CloudConvert-Signature" header.
219- final String signature = " signature" ;
220-
221- // You can find it in your webhook settings.
222- final String secret = " secret" ;
223-
224- // Returns true if signature is valid, and false if signature is invalid
225- final boolean isValid = asyncCloudConvertClient. webhooks(). verify(payload, signature);
226- ```
227-
228204## Unit Tests
229205```
230206$ mvn clean install -U -Punit-tests
0 commit comments