Querying a File in a Repository
Function
This API is used to obtain information about a file in a repository, such as the name, size, and content. Note that the file content is encoded using Base64.
URI
GET /v2/projects/{repo_id}/repository/files
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| repo_id | Yes | Integer | Explanation Repository ID. Go to the code page of the repository to view it. Constraints None. Range 0–2147483647 Default value None. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| file_path | Yes | String | Explanation Complete path of the file. Constraints None. Range None. Default value None. |
| ref | Yes | String | Explanation Commit ID, which is the branch name or tag name of the repository. Constraints None. Range None. Default value None. |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Explanation User token. It can be obtained by calling the corresponding IAM API. The value of X-Subject-Token in the response header is the user token. Constraints None. Range The length range of the character string is [1,100000]. Default value None. |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| error | Error object | Explanation Response error code. Range None. |
| result | FileContentInfo object | Explanation File details. Range None. |
| status | String | Explanation Response status of the API. Range
|
| Parameter | Type | Description |
|---|---|---|
| code | String | Explanation Error code. Range Max. 100 characters in the error code format. |
| message | String | Explanation Error message. Range None. |
| Parameter | Type | Description |
|---|---|---|
| file_name | String | Explanation File name. Range None. |
| file_path | String | Explanation File path. Range None. |
| size | Integer | Explanation File size. Range None. |
| encoding | String | Explanation Document code. Range None. |
| content_sha256 | String | Explanation SHA256-encoded file content. Range None. |
| ref | String | Explanation Branch or tag name. Range None. |
| blob_id | String | Explanation blob sha id Range 40 |
| commit_id | String | Explanation SHA ID of a commit. Range 40 |
| last_commit_id | String | Explanation SHA ID corresponding to the last commit Range 40 |
| content | String | Explanation Base64-encoded file content Range None. |
Example Requests
GET https://{endpoint}/v2/projects/859341/repository/files?README.md&ref=master Example Responses
Status code: 200
OK
{
"result" : {
"size" : 9,
"encoding" : "base64",
"ref" : "master",
"content" : "NDU0NTQ1NDQ1",
"file_name" : "README.md",
"file_path" : "README.md",
"content_sha256" : "e16f4f6c41a79d120484774a625bea8a3c3dcb655aa7c7e793ac48639dc63944",
"blob_id" : "3325fa3142fd66fedc8c3a5218b417f561e0ea2f",
"commit_id" : "a772945ec2765e322cc83e0f467f394effa22cf3",
"last_commit_id" : "a772945ec2765e322cc83e0f467f394effa22cf3"
},
"status" : "success"
} Status Codes
| Status Code | Description |
|---|---|
| 200 | OK |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.