Git blobs
Utilisez l’API REST pour interagir avec un blob (binary large object) Git, type d’objet utilisé pour stocker le contenu de chaque fichier dans un dépôt.
À propos des blobs Git
Un blob (binary large object) Git est le type d’objet utilisé pour stocker le contenu de chaque fichier dans un dépôt. Le hachage SHA-1 du fichier est calculé et stocké dans l’objet blob. Ces points de terminaison vous permettent de lire et d’écrire des objets blob dans votre base de données Git sur GitHub Enterprise Server. Les blobs tirent parti de ces types de médias personnalisés. Plus d’informations sur l’utilisation des types de médias dans l’API sont disponibles ici.
Types de médias personnalisés pour les blobs
Il s’agit des types de médias pris en charge pour les blobs.
application/json
application/vnd.github.raw
Pour plus d’informations, consultez « Types de médias ».
Create a blob
Paramètres pour « Create a blob »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
owner string ObligatoireThe account owner of the repository. The name is not case sensitive. |
repo string ObligatoireThe name of the repository without the |
Nom, Type, Description |
---|
content string ObligatoireThe new blob's content. |
encoding string The encoding used for Default: |
Codes d’état de la réponse HTTP pour « Create a blob »
Code d’état | Description |
---|---|
201 | Created |
403 | Forbidden |
404 | Resource not found |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
Exemples de code pour « Create a blob »
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/blobs \
-d '{"content":"Content of the blob","encoding":"utf-8"}'
Response
Status: 201
{
"url": "https://HOSTNAME/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.
Paramètres pour « Get a blob »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
owner string ObligatoireThe account owner of the repository. The name is not case sensitive. |
repo string ObligatoireThe name of the repository without the |
file_sha string Obligatoire |
Codes d’état de la réponse HTTP pour « Get a blob »
Code d’état | Description |
---|---|
200 | OK |
403 | Forbidden |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
Exemples de code pour « Get a blob »
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/blobs/FILE_SHA
Response
Status: 200
{
"content": "Q29udGVudCBvZiB0aGUgYmxvYg==",
"encoding": "base64",
"url": "https://HOSTNAME/repos/octocat/example/git/blobs/3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"sha": "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"size": 19,
"node_id": "Q29udGVudCBvZiB0aGUgYmxvYg=="
}