Skip to main content

Overview

  1. Get file upload information: Request upload credentials from the server (OSS URL + signature Headers).
  2. Upload the file to OSS: Use the URL and Headers returned in step 1 to PUT the file content to OSS.
  3. Commit the file: Notify the server that the upload is complete to finalize file storage.
The three steps must be executed in order. The file upload cannot be completed if any step is missing.

Step 1: Get file upload information

Call the API POST /v2.0/storage/spaces/files/{parentDentryUuid}/uploadInfos/query, passing the parentDentryUuid (the unique identifier of the parent directory) of the target directory and the operator’s unionId to obtain the credentials required for this upload.
For API details, refer to the Get file upload information documentation. For instructions on calling the API, refer to the documentation on how to call Server APIs.

Key request parameters:

  • parentDentryUuid (Path): The dentryUuid of the target upload directory. To upload to the root directory of a Knowledge Base, obtain the root directory’s dentryUuid in one of the following two ways:
  • unionId (Query): The operator’s unionId. Call the Query user details API to obtain it.
  • protocol (Body): Fixed value HEADER_SIGNATURE.
  • option.preCheckParam.name (Body): The file name (including the extension). It must not contain special characters (*, ", <, >, |) and must not end with ..

Response parameters:

  • uploadKey: The unique identifier for this upload, used in step 3.
  • headerSignatureInfo.resourceUrls: The OSS upload URL, used in step 2.
  • headerSignatureInfo.headers: The OSS request headers, used in step 2.
  • expirationSeconds: The credential expiration time (in seconds). Complete the subsequent steps before it expires.
HTTP example:

Step 2: Upload the file to OSS

Use resourceUrls[0] returned in step 1 as the upload URL and headers as the request headers. Upload the local file content directly to OSS via the HTTP PUT method.
Content-Type must be explicitly set to an empty string. Otherwise, signature verification will fail.
Sample code: Java
Python
Node.js

Step 3: Commit the file

After the OSS upload is complete, call the API POST /v2.0/storage/spaces/files/{parentDentryUuid}/commit to formally write the file into the Knowledge Base directory and complete the entire upload process.

Notes

  • A successful API call returns the file information (dentry), including the file ID, uuid, and the space it belongs to. The upload is complete.
  • For API details, refer to the Commit file documentation. For instructions on calling the API, refer to the documentation on how to call Server APIs.

Key request parameters:

  • parentDentryUuid (Path): Keep consistent with step 1.
  • unionId (Query): The operator’s unionId. Call the Query user details API to obtain it.
  • uploadKey (Body): The uploadKey returned in step 1, used to associate this upload.
  • name (Body): The file name (including the extension).
  • option.conflictStrategy (Body): The file name conflict strategy. Options: AUTO_RENAME (default, automatically rename) or OVERWRITE (overwrite).

HTTP example:

Full process summary

Notes

  • During the upload in step 2, Content-Type must be set to an empty string. Otherwise, OSS signature verification will fail.
  • The upload credentials returned in step 1 have an expiration time (expirationSeconds). Complete steps 2 and 3 before they expire. Otherwise, you must call step 1 again.
  • When the storage space type is USER, only the space owner and administrators have operation permissions. Other employees must first be granted authorization through the “Add Permissions” API.
  • When the storage space type is APP, anyone performing operations must first be granted authorization through the “Add Permissions” API.