Skip to content

File Upload

FileCodeBox provides multiple flexible file upload methods, supporting both regular upload and chunked upload to meet different scenario requirements.

Upload Methods

FileCodeBox supports the following upload methods:

Drag and Drop Upload

Drag files directly to the upload area to start uploading. This is the most convenient upload method.

  1. Open the FileCodeBox homepage
  2. Drag files from your file manager to the upload area
  3. Release the mouse, file upload begins
  4. Get the extraction code after upload completes

Tip

Drag and drop upload supports dragging multiple files simultaneously (depending on theme support).

Click Upload

Click the upload area to select files through the system file picker.

  1. Click the "Select File" button in the upload area
  2. Select the file to upload in the popup file picker
  3. File upload begins after confirming selection
  4. Get the extraction code after upload completes

Paste Upload

Supports pasting images directly from clipboard for upload (supported by some themes).

  1. Copy an image to clipboard (screenshot or copy image)
  2. Use Ctrl+V (Windows/Linux) or Cmd+V (macOS) to paste in the upload area
  3. Image upload starts automatically
  4. Get the extraction code after upload completes

Note

Paste upload only supports image formats, not other file types. Specific support depends on the theme being used.

File Size Limits

Default Limits

SettingDefaultDescription
uploadSize10MBMaximum single file upload size

Modify Upload Limits

Administrators can modify upload size limits through the admin panel or configuration file:

python
# Set maximum upload size to 100MB
uploadSize = 104857600  # 100 * 1024 * 1024

Note

uploadSize is in bytes. Common conversions:

  • 10MB = 10485760
  • 50MB = 52428800
  • 100MB = 104857600
  • 500MB = 524288000
  • 1GB = 1073741824

Exceeding Limit Handling

When an uploaded file exceeds the size limit, the system returns a 403 error:

json
{
  "detail": "Size exceeds limit, maximum is 10.00 MB"
}

Regular Upload API

File Upload Endpoint

POST /share/file/

Content-Type: multipart/form-data

Request parameters:

ParameterTypeRequiredDescription
filefileYesFile to upload
expire_valueintNoExpiration value, default 1
expire_stylestringNoExpiration method, default day

Expiration method options:

ValueDescription
dayExpire by days
hourExpire by hours
minuteExpire by minutes
foreverNever expire
countExpire by download count

Response example:

json
{
  "code": 200,
  "detail": {
    "code": "654321",
    "name": "example.pdf"
  }
}

cURL example:

bash
curl -X POST "http://localhost:12345/share/file/" \
  -F "file=@/path/to/file.pdf" \
  -F "expire_value=7" \
  -F "expire_style=day"

Chunked Upload API

For large files, FileCodeBox supports chunked upload functionality. Chunked upload splits large files into multiple small chunks for separate uploading, supporting resume capability.

Prerequisite

Chunked upload functionality requires administrator enablement: enableChunk=1

Chunked Upload Flow

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│  Initialize │ ──▶ │Upload Chunks│ ──▶ │  Complete   │
│   /init/    │     │  /chunk/    │     │ /complete/  │
└─────────────┘     └─────────────┘     └─────────────┘


                    ┌───────────┐
                    │   Loop    │
                    │each chunk │
                    └───────────┘

1. Initialize Upload

POST /chunk/upload/init/

Request parameters:

json
{
  "file_name": "large_file.zip",
  "file_size": 104857600,
  "chunk_size": 5242880,
  "file_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
ParameterTypeRequiredDefaultDescription
file_namestringYes-Filename
file_sizeintYes-Total file size (bytes)
chunk_sizeintNo5MBChunk size (bytes)
file_hashstringYes-SHA256 hash of the file

Response example:

json
{
  "code": 200,
  "detail": {
    "existed": false,
    "upload_id": "abc123def456789",
    "chunk_size": 5242880,
    "total_chunks": 20,
    "uploaded_chunks": []
  }
}
FieldDescription
existedWhether file already exists (instant upload)
upload_idUpload session ID
chunk_sizeChunk size
total_chunksTotal number of chunks
uploaded_chunksList of already uploaded chunk indices

2. Upload Chunk

POST /chunk/upload/chunk/{upload_id}/{chunk_index}

Path parameters:

ParameterDescription
upload_idUpload session ID returned during initialization
chunk_indexChunk index, starting from 0

Request body:

Content-Type: multipart/form-data

ParameterTypeDescription
chunkfileChunk data

Response example:

json
{
  "code": 200,
  "detail": {
    "chunk_hash": "a1b2c3d4e5f6..."
  }
}

cURL example:

bash
# Upload first chunk (index 0)
curl -X POST "http://localhost:12345/chunk/upload/chunk/abc123def456789/0" \
  -F "chunk=@/path/to/chunk_0"

3. Complete Upload

POST /chunk/upload/complete/{upload_id}

Path parameters:

ParameterDescription
upload_idUpload session ID

Request parameters:

json
{
  "expire_value": 7,
  "expire_style": "day"
}
ParameterTypeRequiredDescription
expire_valueintYesExpiration value
expire_stylestringYesExpiration method

Response example:

json
{
  "code": 200,
  "detail": {
    "code": "789012",
    "name": "large_file.zip"
  }
}

Resume Upload

Chunked upload supports resume functionality. When upload is interrupted:

  1. Call the initialization endpoint again with the same file_hash
  2. Server returns uploaded_chunks list containing already uploaded chunk indices
  3. Client only needs to upload chunks not in the list
  4. Call the complete endpoint after all chunks are uploaded

Example flow:

javascript
// 1. Initialize upload
const initResponse = await fetch('/chunk/upload/init/', {
  method: 'POST',
  body: JSON.stringify({
    file_name: 'large_file.zip',
    file_size: fileSize,
    chunk_size: 5 * 1024 * 1024,
    file_hash: fileHash
  })
});
const { upload_id, uploaded_chunks, total_chunks } = await initResponse.json();

// 2. Upload incomplete chunks
for (let i = 0; i < total_chunks; i++) {
  if (!uploaded_chunks.includes(i)) {
    const chunk = file.slice(i * chunkSize, (i + 1) * chunkSize);
    await fetch(`/chunk/upload/chunk/${upload_id}/${i}`, {
      method: 'POST',
      body: chunk
    });
  }
}

// 3. Complete upload
await fetch(`/chunk/upload/complete/${upload_id}`, {
  method: 'POST',
  body: JSON.stringify({
    expire_value: 7,
    expire_style: 'day'
  })
});

Error Handling

Common Errors

HTTP StatusError MessageCauseSolution
403Size exceeds limitFile exceeds uploadSize limitReduce file size or contact administrator to adjust limit
403Upload rate limitExceeded IP upload rate limitWait for limit time window before retrying
400Invalid expiration typeexpire_style value not in allowed listUse a valid expiration method
404Upload session not foundupload_id invalid or expiredRe-initialize upload
400Invalid chunk indexchunk_index out of rangeCheck if chunk index is correct
400Incomplete chunksChunk count insufficient when completing uploadEnsure all chunks are uploaded

Rate Limiting

The system has rate limits on upload operations to prevent abuse:

SettingDefaultDescription
uploadMinute1Limit time window (minutes)
uploadCount10Maximum uploads within time window

When rate limit is exceeded, you need to wait for the time window to pass before continuing uploads.

Error Response Format

json
{
  "detail": "Error message description"
}

Upload Configuration

SettingTypeDefaultDescription
openUploadint1Enable upload (1=enabled, 0=disabled)
uploadSizeint10485760Maximum upload size (bytes)
enableChunkint0Enable chunked upload (1=enabled, 0=disabled)
uploadMinuteint1Upload rate limit time window (minutes)
uploadCountint10Maximum uploads within time window
expireStylelist["day","hour","minute","forever","count"]Allowed expiration methods

Configuration Example

python
# Allow 100MB file uploads, enable chunked upload
uploadSize = 104857600
enableChunk = 1

# Relax upload rate limit: max 50 uploads per 5 minutes
uploadMinute = 5
uploadCount = 50

# Only allow expiration by days and count
expireStyle = ["day", "count"]

Next Steps

Released under the LGPL-3.0 license