diff --git a/README.md b/README.md index ead1566..e98d5ae 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ const inputFile = fs.createReadStream('./file.pdf'); await cloudConvert.tasks.upload(uploadTask, inputFile, 'file.pdf'); ``` +> **Note on custom streams**: +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. + ## Websocket Events @@ -180,6 +183,15 @@ const cloudConvert = new CloudConvert('api_key', true); > Don't forget to generate MD5 Hashes for the files you will use for testing. +## Setting a Region + +By default, the region in your [account settings](https://cloudconvert.com/dashboard/region) is used. Alternatively, you can set a fixed region: + +```js +// Pass the region as third argument to the constructor +const cloudConvert = new CloudConvert('api_key', false, 'us-east'); +``` + ## Contributing This section is intended for people who want to contribute to the development of this library. diff --git a/lib/CloudConvert.ts b/lib/CloudConvert.ts index eac1e0a..518cf50 100644 --- a/lib/CloudConvert.ts +++ b/lib/CloudConvert.ts @@ -16,6 +16,7 @@ export default class CloudConvert { public readonly apiKey: string; public readonly useSandbox: boolean; + public readonly region: string | null; public axios!: AxiosInstance; public tasks!: TasksResource; @@ -24,9 +25,10 @@ export default class CloudConvert { public webhooks!: WebhooksResource; public signedUrls!: SignedUrlResource; - constructor(apiKey: string, useSandbox = false) { + constructor(apiKey: string, useSandbox = false, region = null) { this.apiKey = apiKey; this.useSandbox = useSandbox; + this.region = region; this.createAxiosInstance(); this.createResources(); @@ -36,7 +38,9 @@ export default class CloudConvert { this.axios = axios.create({ baseURL: this.useSandbox ? 'https://api.sandbox.cloudconvert.com/v2/' - : 'https://api.cloudconvert.com/v2/', + : `https://${ + this.region ? this.region + '.' : '' + }api.cloudconvert.com/v2/`, headers: { Authorization: `Bearer ${this.apiKey}`, 'User-Agent': `cloudconvert-node/v${version} (https://github.com/cloudconvert/cloudconvert-node)` diff --git a/lib/JobsResource.ts b/lib/JobsResource.ts index 8734ac6..ada71e4 100644 --- a/lib/JobsResource.ts +++ b/lib/JobsResource.ts @@ -47,7 +47,11 @@ export default class JobsResource { const response = await this.cloudConvert.axios.get(`jobs/${id}`, { baseURL: this.cloudConvert.useSandbox ? 'https://sync.api.sandbox.cloudconvert.com/v2/' - : 'https://sync.api.cloudconvert.com/v2/' + : `https://${ + this.cloudConvert.region + ? this.cloudConvert.region + '.' + : '' + }sync.api.cloudconvert.com/v2/` }); return response.data.data; } diff --git a/lib/TasksResource.ts b/lib/TasksResource.ts index 06ff47c..4c197bf 100644 --- a/lib/TasksResource.ts +++ b/lib/TasksResource.ts @@ -560,7 +560,11 @@ export default class TasksResource { const response = await this.cloudConvert.axios.get(`tasks/${id}`, { baseURL: this.cloudConvert.useSandbox ? 'https://sync.api.sandbox.cloudconvert.com/v2/' - : 'https://sync.api.cloudconvert.com/v2/' + : `https://${ + this.cloudConvert.region + ? this.cloudConvert.region + '.' + : '' + }sync.api.cloudconvert.com/v2/` }); return response.data.data; }