Skip to content

FileCodeBox API Documentation

API Version: 2.1.0

Table of Contents

Authentication

Some APIs require Authorization header for authentication:

Authorization: Bearer <token>

Get Token

When guest upload is disabled in admin panel (openUpload=0), you need to login first:

bash
curl -X POST "http://localhost:12345/admin/login" \
  -H "Content-Type: application/json" \
  -d '{"password": "FileCodeBox2023"}'

Response Example:

json
{
  "code": 200,
  "msg": "success",
  "detail": {
    "token": "xxx.xxx.xxx",
    "token_type": "Bearer"
  }
}

Share API

Share Text

POST /share/text/

Share text content and get a share code.

Parameters:

ParameterTypeRequiredDefaultDescription
textstringYes-Text content to share
expire_valueintegerNo1Expiration time value
expire_stylestringNo"day"Expiration time unit(day/hour/minute/count/forever)

cURL Example:

bash
# Guest upload (when openUpload=1)
curl -X POST "http://localhost:12345/share/text/" \
  -F "text=This is the text content to share" \
  -F "expire_value=1" \
  -F "expire_style=day"

# When authentication required (openUpload=0)
curl -X POST "http://localhost:12345/share/text/" \
  -H "Authorization: Bearer xxx.xxx.xxx" \
  -F "text=This is the text content to share"

Response Example:

json
{
  "code": 200,
  "msg": "success",
  "detail": {
    "code": "abc123"
  }
}

Share File

POST /share/file/

Upload and share a file, get a share code.

Parameters:

ParameterTypeRequiredDefaultDescription
filefileYes-File to upload
expire_valueintegerNo1Expiration time value
expire_stylestringNo"day"Expiration time unit(day/hour/minute/count/forever)

cURL Example:

bash
# Upload file (default 1 day expiration)
curl -X POST "http://localhost:12345/share/file/" \
  -F "file=@/path/to/file.txt"

# Upload file (7 days expiration)
curl -X POST "http://localhost:12345/share/file/" \
  -F "file=@/path/to/file.txt" \
  -F "expire_value=7" \
  -F "expire_style=day"

# Upload file (10 downloads limit)
curl -X POST "http://localhost:12345/share/file/" \
  -F "file=@/path/to/file.txt" \
  -F "expire_value=10" \
  -F "expire_style=count"

# When authentication required
curl -X POST "http://localhost:12345/share/file/" \
  -H "Authorization: Bearer xxx.xxx.xxx" \
  -F "file=@/path/to/file.txt"

Response Example:

json
{
  "code": 200,
  "msg": "success",
  "detail": {
    "code": "abc123",
    "name": "example.txt"
  }
}

Get File Info

GET /share/select/

Get file information by share code (direct file download).

Parameters:

ParameterTypeRequiredDescription
codestringYesFile share code

cURL Example:

bash
# Download file by extraction code
curl -L "http://localhost:12345/share/select/?code=abc123" -o downloaded_file

Response Example:

json
{
  "code": 200,
  "msg": "success",
  "detail": {
    "code": "abc123",
    "name": "example.txt",
    "size": 1024,
    "text": "File content or download link"
  }
}

Select File

POST /share/select/

Select file by share code.

Parameters:

ParameterTypeRequiredDescription
codestringYesFile share code

Response Example:

json
{
  "code": 200,
  "msg": "success",
  "detail": {
    "code": "abc123",
    "name": "example.txt",
    "size": 1024,
    "text": "File content or download link"
  }
}

Download File

GET /share/download

Download shared file.

Parameters:

ParameterTypeRequiredDescription
keystringYesDownload key
codestringYesFile share code

Admin API

Admin Login

POST /admin/login

Admin login to get token.

Parameters:

ParameterTypeRequiredDescription
passwordstringYesAdmin password

Dashboard Data

GET /admin/dashboard

Get system dashboard data.

Response Example:

json
{
  "code": 200,
  "msg": "success",
  "detail": {
    "totalFiles": 100,
    "storageUsed": "1.5GB",
    "sysUptime": "10 days",
    "yesterdayCount": 50,
    "yesterdaySize": "500MB",
    "todayCount": 30,
    "todaySize": "300MB"
  }
}

File List

GET /admin/file/list

Get system file list.

Parameters:

ParameterTypeRequiredDefaultDescription
pageintegerNo1Current page
sizeintegerNo10Page size
keywordstringNo""Search keyword

Response Example:

json
{
  "code": 200,
  "msg": "success",
  "detail": {
    "page": 1,
    "size": 10,
    "total": 100,
    "data": [
      {
        "id": 1,
        "name": "example.txt",
        "size": 1024,
        "created_at": "2024-01-01 12:00:00"
      }
    ]
  }
}

Delete File

DELETE /admin/file/delete

Delete file from system.

Parameters:

ParameterTypeRequiredDescription
idintegerYesFile ID

Get Config

GET /admin/config/get

Get system configuration.

Update Config

PATCH /admin/config/update

Update system configuration.

Error Response

When an error occurs, the API will return corresponding error message:

json
{
  "code": 422,
  "detail": [
    {
      "loc": ["body", "password"],
      "msg": "Password cannot be empty",
      "type": "value_error"
    }
  ]
}

Status Codes

  • 200: Success
  • 401: Unauthorized
  • 403: Forbidden
  • 404: Not Found
  • 422: Validation Error
  • 500: Internal Server Error

Released under the LGPL-3.0 license