Skip to content

Commit 4568b81

Browse files
authored
feat: add createHiddenFilesBatch to client (#20)
* feat: add createHiddenFilesBatch to client Batch-upload many hidden files in one multipart request, for uploading large 3D-tile sets (point clouds / gaussian splats) without hitting the per-file upload throttle. Pairs with POST /api/item/hidden/batch. * chore: add changeset for createHiddenFilesBatch
1 parent cc9218f commit 4568b81

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

.changeset/batch-hidden-files.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@thatopen/services": minor
3+
---
4+
5+
Add `EngineServicesClient.createHiddenFilesBatch()` to upload many hidden files
6+
in a single request, for large 3D-tile sets (point clouds / gaussian splats)
7+
without hitting the per-file upload throttle. Exports the
8+
`CreateHiddenItemsBatchResult` type.

src/core/client.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { CreateItemResponse, UpdateItemResponse } from '../types/response';
1919
import {
2020
CreateHiddenItemResult,
21+
CreateHiddenItemsBatchResult,
2122
HiddenFileEntity,
2223
Metadata,
2324
} from '../types/files';
@@ -1181,6 +1182,30 @@ export class EngineServicesClient {
11811182
);
11821183
}
11831184

1185+
/**
1186+
* Creates many hidden files attached to a parent item in a single request.
1187+
* Use this instead of many `createHiddenFile` calls when uploading large sets
1188+
* (e.g. 3D Tiles); upload in chunks of up to 100 files per call.
1189+
* @param files - The files to upload.
1190+
* @param parentFileId - The parent item's unique identifier.
1191+
* @returns One result per uploaded file, in order, each with its hidden file ID.
1192+
*/
1193+
async createHiddenFilesBatch(files: (File | Blob)[], parentFileId: string) {
1194+
const formData = new FormData();
1195+
for (const file of files) {
1196+
formData.append('files', file);
1197+
}
1198+
formData.append('parentItemId', parentFileId);
1199+
1200+
return await this.#requestApi<CreateHiddenItemsBatchResult>(
1201+
'POST',
1202+
`${ITEM_PATH}/${HIDDEN_PATH}/batch`,
1203+
{
1204+
body: formData,
1205+
},
1206+
);
1207+
}
1208+
11841209
/**
11851210
* Deletes a hidden file by its ID.
11861211
* @param hiddenId - The hidden file's unique identifier.

src/types/files.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export type CreateHiddenItemResult = {
1313
hiddenFileId: string;
1414
};
1515

16+
export type CreateHiddenItemsBatchResult = {
17+
results: { originalName: string; hiddenFileId: string }[];
18+
};
19+
1620
export type MetadataValue = string | number | boolean | null;
1721

1822
export type Metadata = Record<string, MetadataValue>;

0 commit comments

Comments
 (0)