Skip to content

Commit e2b7517

Browse files
docs: Add convenience methods section to migration guide and improve collections test (box/box-codegen#732) (#637)
1 parent 0e941a7 commit e2b7517

File tree

4 files changed

+58
-16
lines changed

4 files changed

+58
-16
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "d18eeee", "specHash": "630fc85", "version": "1.16.0" }
1+
{ "engineHash": "2667c0e", "specHash": "630fc85", "version": "1.16.0" }

migration-guide.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
- [Configuration](#configuration)
2929
- [As-User header](#as-user-header)
3030
- [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)
3234

3335
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3436

@@ -580,7 +582,9 @@ const newClient = client.withCustomBaseUrls({
580582
});
581583
```
582584

583-
## Webhook validation
585+
## Convenience methods
586+
587+
### Webhook validation
584588

585589
Webhook validation is used to validate a webhook message by verifying the signature and the delivery timestamp.
586590

@@ -611,3 +615,48 @@ let isValid = await WebhooksManager.validateMessage(
611615
{ secondaryKey: secondaryKey } satisfies ValidateMessageOptionalsInput,
612616
);
613617
```
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+
```

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/collections.generated.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ test('testCollections', async function testCollections(): Promise<any> {
7272
await client.folders.updateFolderById(folder.id, {
7373
requestBody: { collections: [] } satisfies UpdateFolderByIdRequestBody,
7474
} satisfies UpdateFolderByIdOptionalsInput);
75-
const collectionItemsAfterRemove: ItemsOffsetPaginated =
76-
await client.collections.getCollectionItems(favouriteCollection.id!);
77-
if (
78-
!(collectionItemsAfterRemove.totalCount! == collectionItems.totalCount!)
79-
) {
80-
throw new Error('Assertion failed');
81-
}
8275
await client.folders.deleteFolderById(folder.id);
8376
});
8477
export {};

0 commit comments

Comments
 (0)