Skip to content

Upload image

POST /api/v5/repos/{owner}/{repo}/img/upload

This endpoint uploads an image to the specified repository. In the request, submit the base64-encoded image file content and the file name in the request body. On success, the relative path and full access address of the image are returned for subsequent reference to the image resource.

Access token support

  • AtomGit user access tokens (AtomGit user access tokens)

Anonymous access allowed?

This endpoint does not allow anonymous access.

Request parameters

Parameter Location Type Required Description
owner path string Yes Address path of the namespace the repository belongs to (the address path of an enterprise, organization, or individual)
repo path string Yes Repository path (path)
access_token query string Yes User authorization code

Request Body:

The request body is application/json, and fields are serialized in snake_case. The fields are described below:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "body": {
      "description": "File content in base64 form (without the Data URL prefix); limited to 20M",
      "type": "string"
    },
    "file_name": {
      "description": "File name",
      "type": "string"
    }
  },
  "required": ["body", "file_name"]
}

Response parameters

The response body is application/json, and fields are serialized in snake_case.

Field Type Always returned Nullable Description
success boolean Yes No Whether the upload succeeded
path string Yes Yes Relative path after upload (e.g. uploads/xxx/test.txt), may be null
full_path string Yes Yes Full access address after upload (https://atomgit.com/...), may be null

Error response

The following error responses use the platform's unified error structure; the actual error field names are subject to what the backend returns.

400 Parameter error

{
  "error_code": 400,
  "error_code_name": "PARAMETER_ERROR",
  "error_message": "File content cannot be empty"
}

401 Unauthenticated

{
  "error_code": 401,
  "error_code_name": "UNAUTHORIZED",
  "error_message": "token not found"
}

HTTP response status codes

Status code Description
200 Success (OK)
400 Parameter error (request body parsing failed or parameter validation failed)
401 Authentication required (missing or invalid access token)
403 Forbidden (no permission)
429 Too many requests; rate limit triggered
500 Internal system error

Request example

Parameter description

  • Replace <owner> with the address path of the namespace the repository belongs to (the address path of an enterprise, organization, or individual);
  • replace <repo> with the repository path (path);
  • replace <token> with your AtomGit user access token;
  • replace <base64_content> with the base64 encoding of the image file content (without the Data URL prefix).

cURL

curl -X POST 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/img/upload?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -d '{
    "body": "<base64_content>",
    "file_name": "test.png"
  }'

JavaScript

// Native fetch (Node.js 18+ / browser)
const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/img/upload?access_token=<token>",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Accept": "application/json",
    },
    body: JSON.stringify({
      body: "<base64_content>",
      file_name: "test.png",
    }),
  }
);

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.post(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/img/upload",
    params={"access_token": "<token>"},
    json={
        "body": "<base64_content>",
        "file_name": "test.png",
    },
    headers={
        "Content-Type": "application/json",
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

Response example

Status code: 200

{
  "success": true,
  "path": "uploads/4c98ad75-729f-49ce-82ab-b41c1f7ffc90/test3.txt",
  "full_path": "https://api.atomgit.com/xiaogang/test/attachment/uploads/4c98ad75-729f-49ce-82ab-b41c1f7ffc90/test3.txt"
}

Error codes

Error code Description
400 Parameter error or the request cannot be parsed
401 Unauthenticated or invalid credentials (missing/invalid access token)
403 Forbidden (no permission)
404 Request path does not exist
405 Request method not supported
429 Too many requests; rate limit triggered
500 Internal system error

Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc