Skip to content

Upload file

POST /api/v5/repos/*/*/file/upload

This endpoint uploads an attachment file to the specified repository. The file size limit is 20M. On success, the relative path and full access address of the file are returned for subsequent access to or reference of the file.

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
file form-data file Yes Attachment to upload; file size limit is 20M

Response parameters

Field Type Always returned Nullable Description
success boolean Yes No Whether the upload succeeded
path string Yes Yes Relative path after a successful upload, may be null
full_path string Yes Yes Full access address after a successful upload, may be null

Error response

A 200/success response alone is not enough: callers need to know what a failure looks like in order to write error handling.

400 Parameter error

{
  "error": "invalid_request",
  "message": "File cannot be empty",
  "field": "file"
}

401 Unauthenticated

{
  "error": "unauthorized",
  "message": "Missing or invalid access token"
}

403 Forbidden

{
  "error": "forbidden",
  "message": "You do not have permission to perform this operation"
}

The actual error field names are subject to what the backend returns.

HTTP response status codes

Status code Description
200 Success (OK)
400 Parameter error (Bad request)
401 Authentication required (Requires authentication)
403 Forbidden
500 Internal system error (Internal server error)

Request example

Parameter description

Meaning of the placeholders in the example: 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 <FILE> with the local file to upload.

cURL

curl -X POST 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/file/upload?access_token=<token>' \
  -H 'Accept: application/json' \
  -F 'file=@<FILE>'

JavaScript

// Native fetch (Node.js 18+ / browser)
const formData = new FormData();
formData.append("file", fileInput.files[0]);

const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/file/upload?access_token=<token>",
  {
    method: "POST",
    headers: {
      "Accept": "application/json",
    },
    body: formData,
  }
);

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>/file/upload?access_token=<token>",
    files={"file": open("<FILE>", "rb")},
    headers={"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 credentials)
403 You do not have permission to perform this operation
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