Upload Dataset File
Upload a dataset file (JSONL, CSV, Parquet, JSON) to an existing dataset using the Knowledgator TypeScript / JavaScript SDK.
Example Usage
1. Upload Buffer / Uint8Array
import { createClient } from '@knowledgator/typescript-sdk';
import { readFile } from 'fs/promises';
const kg = createClient('YOUR_API_KEY');
const fileBuffer = await readFile('./annotations.jsonl');
const response = await kg.datasets.upload('your-dataset-id', {
file: new Uint8Array(fileBuffer),
filename: 'annotations.jsonl'
});
console.log('Upload result:', response);
2. Upload from In-Memory String Content
import { createClient } from '@knowledgator/typescript-sdk';
const kg = createClient('YOUR_API_KEY');
const jsonContent = JSON.stringify([
{ text: "Great product!", label: "positive" },
{ text: "Poor battery life", label: "negative" }
]);
const response = await kg.datasets.upload('your-dataset-id', {
file: new TextEncoder().encode(jsonContent),
filename: 'samples.json'
});
console.log('Upload status:', response.status);
3. Uploading During Dataset Creation
You can also provide the file directly when creating a dataset:
import { createClient } from '@knowledgator/typescript-sdk';
import { readFile } from 'fs/promises';
const kg = createClient('YOUR_API_KEY');
const buffer = await readFile('./dataset.json');
const dataset = await kg.datasets.create({
name: 'my_classification_dataset',
type: 'comprehend-it',
format: 'json',
short_description: 'Customer review sentiment dataset',
file: new Uint8Array(buffer),
filename: 'dataset.json'
});
console.log('Created dataset ID:', dataset.id);
Method Parameters
kg.datasets.upload(datasetId, request)
| Parameter | Type | Required | Description |
|---|---|---|---|
datasetId | string | Yes | Target dataset ID. |
request.file | Uint8Array | Buffer | Blob | Yes | Binary data of the file to upload. |
request.filename | string | No | Original filename (e.g. 'annotations.jsonl'). |
request.format | DatasetFormat | No | Optional format override ('jsonl', 'csv', 'parquet', 'json'). |