Skip to content

Commit 9346041

Browse files
committed
add region setting
1 parent 999c39c commit 9346041

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ const inputFile = fs.createReadStream('./file.pdf');
9292

9393
await cloudConvert.tasks.upload(uploadTask, inputFile, 'file.pdf');
9494
```
95+
> **Note on custom streams**:
96+
The length of the stream needs to be known prior to uploading. The SDK automatically detects the file size of file-based read streams. If you are using a custom stream, you need to pass a `filesize` as fourth parameter to the `upload()` method.
97+
9598

9699
## Websocket Events
97100

@@ -180,6 +183,15 @@ const cloudConvert = new CloudConvert('api_key', true);
180183

181184
> Don't forget to generate MD5 Hashes for the files you will use for testing.
182185
186+
## Setting a Region
187+
188+
By default, the region in your [account settings](https://cloudconvert.com/dashboard/region) is used. Alternatively, you can set a fixed region:
189+
190+
```js
191+
// Pass the region as third argument to the constructor
192+
const cloudConvert = new CloudConvert('api_key', false, 'us-east');
193+
```
194+
183195
## Contributing
184196

185197
This section is intended for people who want to contribute to the development of this library.

lib/CloudConvert.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class CloudConvert {
1616

1717
public readonly apiKey: string;
1818
public readonly useSandbox: boolean;
19+
public readonly region: string | null;
1920

2021
public axios!: AxiosInstance;
2122
public tasks!: TasksResource;
@@ -24,9 +25,10 @@ export default class CloudConvert {
2425
public webhooks!: WebhooksResource;
2526
public signedUrls!: SignedUrlResource;
2627

27-
constructor(apiKey: string, useSandbox = false) {
28+
constructor(apiKey: string, useSandbox = false, region = null) {
2829
this.apiKey = apiKey;
2930
this.useSandbox = useSandbox;
31+
this.region = region;
3032

3133
this.createAxiosInstance();
3234
this.createResources();
@@ -36,7 +38,9 @@ export default class CloudConvert {
3638
this.axios = axios.create({
3739
baseURL: this.useSandbox
3840
? 'https://api.sandbox.cloudconvert.com/v2/'
39-
: 'https://api.cloudconvert.com/v2/',
41+
: `https://${
42+
this.region ? this.region + '.' : ''
43+
}api.cloudconvert.com/v2/`,
4044
headers: {
4145
Authorization: `Bearer ${this.apiKey}`,
4246
'User-Agent': `cloudconvert-node/v${version} (https://github.com/cloudconvert/cloudconvert-node)`

lib/JobsResource.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export default class JobsResource {
4747
const response = await this.cloudConvert.axios.get(`jobs/${id}`, {
4848
baseURL: this.cloudConvert.useSandbox
4949
? 'https://sync.api.sandbox.cloudconvert.com/v2/'
50-
: 'https://sync.api.cloudconvert.com/v2/'
50+
: `https://${
51+
this.cloudConvert.region
52+
? this.cloudConvert.region + '.'
53+
: ''
54+
}sync.api.cloudconvert.com/v2/`
5155
});
5256
return response.data.data;
5357
}

lib/TasksResource.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,11 @@ export default class TasksResource {
560560
const response = await this.cloudConvert.axios.get(`tasks/${id}`, {
561561
baseURL: this.cloudConvert.useSandbox
562562
? 'https://sync.api.sandbox.cloudconvert.com/v2/'
563-
: 'https://sync.api.cloudconvert.com/v2/'
563+
: `https://${
564+
this.cloudConvert.region
565+
? this.cloudConvert.region + '.'
566+
: ''
567+
}sync.api.cloudconvert.com/v2/`
564568
});
565569
return response.data.data;
566570
}

0 commit comments

Comments
 (0)