Upload local files¶
Upload local files for use in creating or appending knowledge base sources. Successful upload only means that the file has been saved, but does not mean that the content is retrievable.
POST https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/local-files/upload
Preparation before calling¶
First query the knowledge base list to obtain the target knowledge base ID. Prepare a personal access token and target workspace ID that has access to the target workspace.
The example below uses:
$AI_STUDIO_API_KEY: The actual personal access token, passed through theX-API-KeyHeader.$WORKSPACE_ID: Target workspace ID, passed throughX-Workspace-IDHeader.$MODEL_ID: Target knowledge base ID.
The request type of this interface is multipart/form-data; the example uses curl -F to submit the file and do not add Content-Type: application/json.
Request example¶
curl -X POST "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/local-files/upload" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-F "file=@./product-guide.pdf"
Path parameters¶
Parameters |
Type |
Description |
|---|---|---|
|
integer |
Target knowledge base ID. |
Form fields¶
Field |
Type |
Required |
Description |
|---|---|---|---|
|
file |
Yes |
The local file to upload. |
Successful response¶
Returns 200 on success. Save data.file_id, construct the value into the local_file source, and then call the add data source interface.
{
"code": "OK",
"msg": "OK",
"data": {
"file_id": "file_01"
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
string |
ID of the uploaded file; use this value when adding a local file source. |
Error response¶
{
"code": "ErrParamInvalid",
"msg": "file is required",
"data": null
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
The multipart file named |
Resubmit the file using |
|
|
The API Key is invalid or has expired. |
Check API Key. |
|
|
The caller does not have permission to upload files to the knowledge base. |
Check workspace and object authorization. |
|
|
The knowledge base does not exist or is not visible to the current caller. |
Relist the knowledge base and confirm the ID. |
|
|
The service failed to store the file. |
Keep the desensitized response information and try again. |
Follow-up operations¶
Use data.file_id Add data source.