Skip to content

Commit a804d45

Browse files
committed
move to blobs
1 parent b3a03c2 commit a804d45

4 files changed

Lines changed: 5 additions & 28 deletions

File tree

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,11 @@ const job = await cloudConvert.jobs.create({
8888

8989
const uploadTask = job.tasks.filter(task => task.name === 'upload-my-file')[0];
9090

91-
const inputFile = fs.createReadStream('./file.pdf');
91+
const inputFile = fs.openAsBlob('./file.pdf');
9292

9393
await cloudConvert.tasks.upload(uploadTask, inputFile, 'file.pdf');
9494
```
9595

96-
> **Note on custom streams**:
97-
> 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.
98-
9996
## Websocket Events
10097

10198
The node SDK can subscribe to events of the [CloudConvert socket.io API](https://cloudconvert.com/api/v2/socket#socket).

lib/CloudConvert.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io from 'socket.io-client';
2-
import FormData from 'form-data';
32
import { version } from '../package.json';
43
import JobsResource, { type JobEventData } from './JobsResource';
54
import SignedUrlResource from './SignedUrlResource';
@@ -59,10 +58,7 @@ export default class CloudConvert {
5958
method,
6059
headers: {
6160
Authorization: `Bearer ${this.apiKey}`,
62-
'User-Agent': `cloudconvert-node/v${version} (https://github.com/cloudconvert/cloudconvert-node)`,
63-
...(parameters instanceof FormData
64-
? parameters.getHeaders()
65-
: {})
61+
'User-Agent': `cloudconvert-node/v${version} (https://github.com/cloudconvert/cloudconvert-node)`
6662
},
6763
body:
6864
parameters instanceof FormData

lib/TasksResource.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import FormData, { type Stream } from 'form-data';
21
import CloudConvert from './CloudConvert';
32
import { type JobTask } from './JobsResource';
4-
import { ReadStream, statSync } from 'fs';
53

64
export type TaskEvent = 'created' | 'updated' | 'finished' | 'failed';
75
export type TaskStatus = 'waiting' | 'processing' | 'finished' | 'error';
@@ -589,9 +587,8 @@ export default class TasksResource {
589587

590588
async upload(
591589
task: Task | JobTask,
592-
stream: Stream,
593-
filename: string | null = null,
594-
size: number | null = null
590+
stream: Blob,
591+
filename?: string
595592
): Promise<any> {
596593
if (task.operation !== 'import/upload') {
597594
throw new Error('The task operation is not import/upload');
@@ -602,22 +599,10 @@ export default class TasksResource {
602599
}
603600

604601
const formData = new FormData();
605-
606602
for (const parameter in task.result.form.parameters) {
607603
formData.append(parameter, task.result.form.parameters[parameter]);
608604
}
609-
610-
const fileOptions: { filename?: string; knownLength?: number } = {};
611-
612-
if (filename) {
613-
fileOptions.filename = filename;
614-
}
615-
if (size) {
616-
fileOptions.knownLength = size;
617-
} else if (stream instanceof ReadStream) {
618-
fileOptions.knownLength = statSync(stream.path).size;
619-
}
620-
formData.append('file', stream, fileOptions);
605+
formData.append('file', stream, filename);
621606

622607
return await this.cloudConvert.call(
623608
'POST',

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"node": ">=19.8.0"
2020
},
2121
"dependencies": {
22-
"form-data": "^4.0.0",
2322
"socket.io-client": "^4.7.4"
2423
},
2524
"devDependencies": {

0 commit comments

Comments
 (0)