Help Center/ KooDrive/ API Reference/ API/ File Management/ Creating File Metadata
Updated on 2024-07-30 GMT+08:00

Creating File Metadata

Function

Create the metadata of the uploaded file. If flash upload is not hit, the upload process is triggered. When flash upload is hit, the file upload is complete.

URI

POST /koodrive/ose/v1/files/create

Request Parameters

Table 1 Request header parameters

Parameter

Mandatory

Type

Description

Authorization

Yes

String

Access token. Token authentication is used to call KooDrive APIs. A token indicates the permission. When an API is called, the token is added to the request header to obtain the operation permission. For details about how to obtain an access token, see the corresponding developer guide. The format is Bearer+{access_token}.

X-Traceid

No

String

Message log trace ID. The value contains 58 bits.

language

No

String

Language code, which complies with the internationalization specifications. For example, en-US indicates English (United States). English (United States) is used by default.

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

createdTime

No

String

Time when the file is created. The format is yyyy-MM-dd'T'HH:mm:ss'Z', for example, 2023-08-18T05:43:49Z.

description

No

String

File description.

Maximum: 512

mimeType

No

String

Resource type.

fileName

Yes

String

File name, which cannot contain <>|:"*? /. The value cannot be two periods (..), a period (.), or a space.

Maximum: 80

fileType

Yes

String

File type, which is customizable.

parentFolder

Yes

Array of strings

Parent directory ID list. If the target directory is a root directory, the value is root.

Currently, only one parent directory is supported. If multiple parent directory IDs are passed, only the first one is used.

sha256

No

String

Complete file digest calculated using SHA256.

length

Yes

Long

File size, in bytes.

When uploadMode is set to put, the value must be less than or equal to 5 GB.

If uploadMode is set to multipart, the value must be less than or equal to 200 GB.

uploadMode

Yes

String

Upload mode.

  • multipart: multipart upload.

  • put: single file upload.

uploadType

Yes

Integer

Upload type.

  • 0: common upload (not supported yet).

  • 1: multipart upload.

  • 2: versioning upload (not supported yet).

autoRename

Yes

Integer

Duplicate name policy.

  • 2: Forcibly renames a file with an existing name by adding a timestamp to the end of the file name.

  • 3: Rejects files with the same name. A file with an existing name cannot be created.

  • 4: Does not create a file if files with the same name have the same SHA256 value, or, uses the forcible renaming logic.

multiParts

No

Array of MultiPartInfo objects

Part information list.

containerId

Yes

String

ID of the target space to which the file is uploaded.

preHash

No

String

Digest of the first 1 KB of the file calculated using SHA256.

Table 3 MultiPartInfo

Parameter

Mandatory

Type

Description

partNumber

Yes

Integer

Part No.

Minimum: 1

Maximum: 10000

partSize

Yes

Long

Part length. The value range is [5,242,880, 5,368,709,120]. The value range of the last part is [0, 5,368,709,120].

Minimum value: 0. Maximum value: 5,368,709,120.

partOffset

No

Long

Total length (in bytes) to the last data block. This parameter is valid only during concurrent multipart upload. The size of all parts except the last one must be a multiple of 64 bytes.

hashCtx

No

Array of longs

Context used to iteratively calculate SHA256. This field is valid only during concurrent multipart upload. For SHA1, the value is the first to fifth 32-bit variables of the SHA1 of the previous data block. For SHA256, the value is the first to eighth 32-bit variables of the SHA256 of the previous data block.

This parameter is mandatory for all parts except the first one in concurrent multipart upload.

uploadUrl

No

String

URL for uploading a file. This parameter is returned.

partId

No

String

Part object ID.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

fileId

String

File ID.

rapidUpload

Boolean

Whether flash upload is hit. true indicates that flash upload is hit.

containerId

String

ID of the space where the file is located.

fileName

String

Name of the uploaded file. If the file is not renamed, the value is the same as the file name in the request parameter.

uploadId

String

File upload ID.

parentFolder

Array of strings

ID of the parent directory where the uploaded file is located.

exist

Boolean

Whether the file exists. This parameter is used only when the input parameter autoRename is set to 4. If the file names and SHA256 values are the same, true is returned.

multiParts

Array of MultiPartInfo objects

Part information, which is returned during multipart upload (when uploadMode is set to multipart).

matchedPreHash

Boolean

Whether a matching prehash exists.

code

String

Response code.

msg

String

Response information.

Table 5 MultiPartInfo

Parameter

Type

Description

partNumber

Integer

Part No.

Minimum: 1

Maximum: 10000

partSize

Long

Part length. The value range is [5,242,880, 5,368,709,120]. The value range of the last part is [0, 5,368,709,120].

Minimum value: 0. Maximum value: 5,368,709,120.

partOffset

Long

Total length (in bytes) to the last data block. This parameter is valid only during concurrent multipart upload. The size of all parts except the last one must be a multiple of 64 bytes.

hashCtx

Array of longs

Context used to iteratively calculate SHA256. This field is valid only during concurrent multipart upload. For SHA1, the value is the first to fifth 32-bit variables of the SHA1 of the previous data block. For SHA256, the value is the first to eighth 32-bit variables of the SHA256 of the previous data block.

This parameter is mandatory for all parts except the first one in concurrent multipart upload.

uploadUrl

String

URL for uploading a file. This parameter is returned.

partId

String

Part object ID.

Example Requests

Creates file metadata in multipart upload mode. In this example, a part is specified. The upload link of the part is returned in the subsequent response. The part needs to be uploaded through a PUT request.

POST /koodrive/ose/v1/files/create

Authorization:Bearer+10f88*********4791e9ff

{
    "containerId": "IAADfsBFCO6WtAtuA9add2fea594e4e75b8feb8474ef236",
    "parentFolder": [
        "root"
    ],
    "createdTime": "2020-05-18T01:43:49Z",
    "mimeType": "application/x-zip-compressed",
    "fileType": 35,
    "fileName": "demo.zip",
    "sha256": "08a784aeb181506391c20c6355f881dc363d8c3e0739d295e5d6f410d05dbc69",
    "length": 22106481,
    "uploadMode": "multipart",
    "uploadType": 1,
    "autoRename": 2,
    "multiParts": [
        {
            "partNumber": 1,
            "partOffset": 0,
            "partSize": 22106481
        }
    ],
    "description": ""
}

Example Responses

Status code: 200

Information returned after the first step of uploading a file is complete.

{
  "fileId" : "FnkL1QhXj8muHBuSWCHtFFY8Azue44Snr",
  "containerId" : "IAADfsBFCO6WtAtuA9add2fea594e4e75b8feb8474ef236",
  "fileName" : "test_20240104_105403.zip",
  "uploadId" : "0000018CD26464022026422966B8879A",
  "parentFolder" : [ "DEUI7pa0C24ArootIAADfsBFCO6WtAtuA9add2fea594e4e75b8feb8474ef236" ],
  "exist" : false,
  "multiParts" : [ {
    "partNumber" : 1,
    "partSize" : 22106481,
    "partOffset" : 0,
    "uploadUrl" : "https://b10-obs-ykj-uat-01.obs.cidc-rp-2006.joint.cmecloud.cn/ff6b221b4b474c829c1cd5037f1504ca086?partNumber=1&uploadId=0000018CD26464022026422966B8879A&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240104T025403Z&X-Amz-SignedHeaders=content-length%3Bhost&X-Amz-Expires=3600&X-Amz-Credential=MKRISPBZAJWFHNBJ5WLB%2F20240104%2Fcidc-rp-2006%2Fs3%2Faws4_request&X-Amz-Signature=39b9b620c8de901682675059cfcfa9902a13fb5c6ab38fe1451763feb6a8323c"
  } ],
  "code" : 0,
  "msg" : "Success."
}

Status Codes

Status Code

Description

200

Information returned after the first step of uploading a file is complete.