|
28 | 28 | - [Configuration](#configuration) |
29 | 29 | - [As-User header](#as-user-header) |
30 | 30 | - [Custom Base URLs](#custom-base-urls) |
31 | | -- [Webhook validation](#webhook-validation) |
| 31 | +- [Convenience methods](#convenience-methods) |
| 32 | + - [Webhook validation](#webhook-validation) |
| 33 | + - [Chunked upload of big files](#chunked-upload-of-big-files) |
32 | 34 |
|
33 | 35 | <!-- END doctoc generated TOC please keep comment here to allow auto update --> |
34 | 36 |
|
@@ -580,7 +582,9 @@ const newClient = client.withCustomBaseUrls({ |
580 | 582 | }); |
581 | 583 | ``` |
582 | 584 |
|
583 | | -## Webhook validation |
| 585 | +## Convenience methods |
| 586 | + |
| 587 | +### Webhook validation |
584 | 588 |
|
585 | 589 | Webhook validation is used to validate a webhook message by verifying the signature and the delivery timestamp. |
586 | 590 |
|
@@ -611,3 +615,48 @@ let isValid = await WebhooksManager.validateMessage( |
611 | 615 | { secondaryKey: secondaryKey } satisfies ValidateMessageOptionalsInput, |
612 | 616 | ); |
613 | 617 | ``` |
| 618 | + |
| 619 | +### Chunked upload of big files |
| 620 | + |
| 621 | +For large files or in cases where the network connection is less reliable, you may want to upload the file in parts. |
| 622 | +This allows a single part to fail without aborting the entire upload, and failed parts are being retried automatically. |
| 623 | + |
| 624 | +**Legacy (`Box Node SDK`):** |
| 625 | + |
| 626 | +In the old SDK, you could use the `getChunkedUploader()` method to create a chunked uploader object. |
| 627 | +Then, you would call the `start()` method to begin the upload process. |
| 628 | +The `getChunkedUploader()` method requires the `parentFolderId`, `fileSize`, `fileName` and `stream` parameters. |
| 629 | + |
| 630 | +```typescript |
| 631 | +var stream = fs.createReadStream('/path/to/file.txt'); |
| 632 | +var fileName = 'new_name.txt'; |
| 633 | +var fileSize = fs.statSync('/path/to/file.txt').size; |
| 634 | +var parentFolderId = '0'; |
| 635 | +client.files |
| 636 | + .getChunkedUploader(parentFolderId, fileSize, fileName, stream) |
| 637 | + .then((uploader) => uploader.start()) |
| 638 | + .then((file) => { |
| 639 | + /* ... */ |
| 640 | + }); |
| 641 | +``` |
| 642 | + |
| 643 | +**Modern (`Box TypeScript SDK`):** |
| 644 | + |
| 645 | +In the new SDK, the equivalent method is `chunked_uploads.uploadBigFile()`. It accepts a `Readable` object |
| 646 | +as the `file` parameter, and the `fileName` and `fileSize` parameters are now passed as arguments. |
| 647 | +The `parentFolderId` parameter is also required to specify the folder where the file will be uploaded. |
| 648 | + |
| 649 | +```typescript |
| 650 | +import { File } from 'box-typescript-sdk-gen/lib/schemas/file.generated.js'; |
| 651 | + |
| 652 | +var fileByteStream = fs.createReadStream('/path/to/file.txt'); |
| 653 | +var fileName = 'new_name.txt'; |
| 654 | +var fileSize = fs.statSync('/path/to/file.txt').size; |
| 655 | +var parentFolderId = '0'; |
| 656 | +const uploadedFile: File = await client.chunkedUploads.uploadBigFile( |
| 657 | + fileByteStream, |
| 658 | + fileName, |
| 659 | + fileSize, |
| 660 | + parentFolderId, |
| 661 | +); |
| 662 | +``` |
0 commit comments