Git Blob
REST API를 사용하여 리포지토리에 각 파일의 콘텐츠를 저장하는 데 사용되는 개체 형식인 Git Blob(이진 큰 개체)과 상호 작용합니다.
Git Blob 정보
Git BLOB(Binary Large Object)은 각 파일의 콘텐츠를 리포지토리에 저장하는 데 사용되는 개체 형식입니다. 파일의 SHA-1 해시는 계산되어 BLOB 개체에 저장됩니다. 엔드포인트를 사용하면 GitHub에서 Git 데이터베이스에 BLOB 개체를 읽고 쓸 수 있습니다. BLOB은 사용자 지정 미디어 유형을 활용합니다. API에서 미디어 유형의 사용에 대한 자세한 내용은 여기를 참조하세요.
BLOB에 대한 사용자 지정 미디어 유형
다음은 BLOB에 대해 지원되는 미디어 유형입니다.
application/json
application/vnd.github.raw
자세한 내용은 “미디어 유형”을 참조하세요.
Create a blob
매개 변수
| Headers |
|---|
| Name, Type, Description |
acceptstringSetting to |
| Path parameters |
| Name, Type, Description |
ownerstringRequiredThe account owner of the repository. The name is not case sensitive. |
repostringRequiredThe name of the repository. The name is not case sensitive. |
| Body parameters |
| Name, Type, Description |
contentstringRequiredThe new blob's content. |
encodingstringThe encoding used for Default: |
HTTP 응답 상태 코드
| 상태 코드 | 설명 |
|---|---|
201 | Created |
403 | Forbidden |
404 | Resource not found |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
코드 샘플
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/git/blobs \
-d '{"content":"Content of the blob","encoding":"utf-8"}'Response
Status: 201{
"url": "https://api.github.com/repos/octocat/example/git/blobs/3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"sha": "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15"
}Get a blob
The content in the response will always be Base64 encoded.
Note: This API supports blobs up to 100 megabytes in size.
매개 변수
| Headers |
|---|
| Name, Type, Description |
acceptstringSetting to |
| Path parameters |
| Name, Type, Description |
ownerstringRequiredThe account owner of the repository. The name is not case sensitive. |
repostringRequiredThe name of the repository. The name is not case sensitive. |
file_shastringRequired |
HTTP 응답 상태 코드
| 상태 코드 | 설명 |
|---|---|
200 | OK |
403 | Forbidden |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
코드 샘플
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/git/blobs/FILE_SHAResponse
Status: 200{
"content": "Q29udGVudCBvZiB0aGUgYmxvYg==",
"encoding": "base64",
"url": "https://api.github.com/repos/octocat/example/git/blobs/3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"sha": "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"size": 19,
"node_id": "Q29udGVudCBvZiB0aGUgYmxvYg=="
}