Training File Upload API
Purpose
This API uploads files for the chatbot’s knowledge base. TXT and PDF files are supported.
URL
HTTP method
POST
Headers
| Headers | Value | Description |
|---|---|---|
| Content-Type | multipart/form-data | Use multipart/form-data to send the file. |
| Authorization | Bearer <api_key> | Use the API key provided in Install in the Sidetalk dashboard. |
Parameters (body)
Plain Text
multipart/form-dataBody parameters sent in this format.
| Parameter | Type | Required | Description |
|---|---|---|---|
| file | File | Yes | The file object to upload. (Supported formats: .txt, .pdf) TXT: up to 3MB — PDF: up to 20MB |
Example request
Bash
curl-XPOST"https://api.sidetalk.ai/v1/knowledge/file"\
-H"Authorization: Bearer ${API_KEY}"\
-F"file=@/path/to/document.pdf"Response format
A JSON response indicates the file was successfully uploaded to storage.
Caution: this response only confirms file storage, not completion of knowledge processing. AI data training runs asynchronously in the background.
Response body (success)
JSON
{
"success":true,
"result": {
"file_name":"manual.pdf",
"file_size":1048576,
"file_type":"application/pdf"
}
}Response fields
1. Basic response
| Field | Type | Description |
|---|---|---|
| success | Boolean | Whether the request succeeded. (true) |
2. Result data (result)
| Field | Type | Description |
|---|---|---|
| file_name | String | The original name of the uploaded file. |
| file_size | Number | The uploaded file size in bytes. |
| file_type | String | The uploaded file MIME type. (Example: application/pdf) |
Example code (JavaScript)
Upload a file
JavaScript
async function uploadKnowledgeFile(fileObject) {
const baseUrl = "https://api.sidetalk.ai/v1/knowledge/file";
// FormData 생성
const formData = new FormData();
formData.append("file", fileObject); // <input type="file">에서 가져온 File 객체
try {
const response = await fetch(baseUrl, {
method: "POST",
headers: {
"Authorization": "Bearer [API_KEY]"
// Content-Type 헤더는 브라우저가 자동으로 multipart/form-data로 설정하므로 생략
},
body: formData
});
if (!response.ok) {
const errorData = await response.json();
console.error("Upload Failed:", errorData.error || 'Unknown error');
return;
}
const result = await response.json();
console.log("Upload Success:", result);
} catch (error) {
console.error("Error uploading file:", error);
}
}Error response
If processing fails, success: false is returned with an error message.
Response body
JSON
{
"success":false,
"error":"PDF file size must be 20MB or less."
}Example error messages
- No file uploaded or invalid format.: no file attached or an invalid format
- Only txt and pdf files are allowed.: unsupported extension
- Text file size must be 3MB or less.: TXT size limit exceeded
- PDF file size must be 20MB or less.: PDF size limit exceeded
- Invalid text file. Binary content detected.: binary data found in a text file
- Invalid PDF file. Signature mismatch.: damaged or forged PDF header
Error response fields
| Field | Type | Description |
|---|---|---|
| success | Boolean | Whether the request failed. (false) |
| error | String | Detailed information about the error. |
