Knowledge Base File Upload
File Document Integration
Endpoint
POST https://api.maiagent.ai/api/knowledge-bases/{knowledgeBasePk}/files/
Description
After upload is complete, submit file-related information to the knowledge base for recording and processing.
Path Parameters
knowledgeBasePk
string
Yes
Knowledge Base ID (UUID format)
Request Parameters
files
array
Yes
Array containing file information
files[].file
string
Yes
File path in cloud storage
files[].filename
string
Yes
Desired filename for saving
files[].knowledgeBase
string
No
Knowledge Base ID (UUID format) Main purpose: This parameter is mainly used for API backward compatibility and validation (can be omitted)
files[].parser
string
No
Parser ID (UUID format)
files[].labels
array
No
Label array
files[].labels[].id
string
No
Label ID (UUID format)
files[].labels[].name
string
No
Label name
files[].rawUserDefineMetadata
object
No
User-defined metadata
Example Request
Example Response
Error Handling
The API may return the following error status codes and messages:
400 - Bad Request
Missing Required Fields
Fix Suggestion: Check the request JSON structure to ensure it includes the required files array and that each file item has filename and file fields.
Invalid File Format
Fix Suggestion: Verify that the file field contains the correct file path format. The path should be a complete cloud storage path, e.g., media/chatbots/chatbot-file/xxx.xlsx.
Invalid UUID Format
Fix Suggestion: Ensure the knowledgeBasePk in the path is a valid UUID format (e.g., 550e8400-e29b-41d4-a716-446655440000). You can first call the knowledge base list API to get the correct ID.
Duplicate File Upload
Fix Suggestion: The file (based on files[].file path) already exists in the knowledge base. If you need to re-upload the same content, please delete the old file record first; if updating file content, you need to re-upload the file to cloud storage to get a new files[].file path.
Unsupported File Type
Fix Suggestion: Check if the file extension is in the supported list (.pdf, .docx, .xlsx, .txt, .mp3, etc.). If the file format is not supported, please convert it to a supported format before uploading.
File Size Exceeds Limit
Fix Suggestion: File size exceeds 100MB limit. Please compress the file, split it into smaller files, or remove unnecessary content before re-uploading.
Invalid Content Type
Fix Suggestion: The actual format of the file doesn't match its extension, or the extension is not supported by the system. Please verify the file format is correct and use the correct extension.
File Not Provided
Fix Suggestion: File content is missing in the request. Ensure the file field contains a valid file path and the file has been properly uploaded to cloud storage.
401 - Authentication Failed
Invalid or Missing API Key
Fix Suggestion: Check if the request header includes the correct Authorization field. Format should be: Authorization: Api-Key YOUR_API_KEY.
Invalid API Key Format
Fix Suggestion: Verify the API Key format is correct. Check if you're using the correct prefix Api-Key instead of Bearer, and ensure the API Key itself has no extra spaces or characters.
403 - Permission Denied
Organization File Upload Limit
Fix Suggestion: Organization has reached its file upload capacity limit. Please delete unnecessary files to free up space, or contact administrator to upgrade the organization plan for more capacity.
No Permission to Access Knowledge Base
Fix Suggestion: Verify that the current API Key's user or organization has permission to access the knowledge base. Contact administrator to check permission settings, or use an API Key with proper permissions.
404 - Resource Not Found
Knowledge Base Not Found
Fix Suggestion: Verify the knowledgeBasePk parameter is correct. You can first call the knowledge base list API to confirm if the knowledge base exists, or check if it has been deleted.
Parser Not Found
Fix Suggestion: Check if the provided parser ID is correct. You can omit this field to use the system default parser, or call the parser list API to get a valid parser ID.
Label Not Found
Fix Suggestion: Verify that the provided label IDs exist in the specified knowledge base. You can first call the knowledge base labels list API to get valid label IDs, or remove non-existent label IDs.
413 - Request Entity Too Large
File Size Exceeds Server Limit
Fix Suggestion: File size exceeds server processing limit. Split the file into multiple smaller files, or use file compression tools to reduce file size before re-uploading.
422 - Unprocessable Entity
File Parsing Failed (e.g., Corrupted Excel File)
Fix Suggestion: File may be corrupted or in an abnormal format. Try opening the file with Excel or other software and re-save it, or copy the content to a new file before re-uploading.
File Encoding Issues
Fix Suggestion: File encoding is abnormal or file is corrupted. For text files, ensure they are saved with UTF-8 encoding; for other files, check file integrity and regenerate the file.
500 - Server Error
File Processing Failed
Fix Suggestion: Internal server error, usually temporary. Please try again later, if the problem persists, contact technical support and provide the time of error occurrence and file information.
Database Connection Failed
Fix Suggestion: Server database connection issue, usually temporary. Please try again later, if the problem persists, contact technical support.
Last updated
Was this helpful?
