Skip to content

API Token File Uploads

API Token uploads are intended for scripts, automation jobs, and third-party programs. You do not need to open the web UI. As long as you provide the site URL, token, local file path, and a real upload channel, the file can be uploaded to ImgHost and the response will include the file URL.

Edit API Token

Before You Start

Open the admin panel, then go to:

text
System Settings -> Security Settings -> API Token

When creating or editing the API Token, make sure it has the upload permission and uses a real default upload channel. API Token uploads do not use the Smart Dispatch entry, and scripts should also pass a real channel.

Download The Upload Scripts

The documentation package provides two Node.js scripts:

ScriptPurpose
single-request upload scriptCalls /upload once. Useful for small files and connectivity tests.
chunked upload scriptUses API Token chunking, direct upload, or platform upload sessions. Recommended for large files.

Node.js 18 or later is required.

List Available Channels

Both scripts can list the upload channels available to the current API Token:

powershell
node imghost-token-single-upload.mjs --base-url "https://your-domain" --token "your API Token" --list-channels
node imghost-token-chunk-upload.mjs --base-url "https://your-domain" --token "your API Token" --list-channels

When listing channels, --file and --channel are not required. The response includes the default upload channel, upload channel keys, child channel names, and load-balance status. Secrets, refresh tokens, and other sensitive configuration values are not returned.

Choosing An Upload Mode

ModeBest ForDescription
Single-request uploadSmall files, simple scripts, connectivity testsSends the whole file to /upload in one request.
Chunked uploadLarge files or files likely to time outThe script chooses the channel-specific chunked, direct, or upload-session flow.

For larger files, use the chunked upload script first. Single-request uploads are limited by Cloudflare request size, Worker memory, and each platform's own limits.

Single-Request Upload

The single-request script sends one request to /upload.

powershell
node imghost-token-single-upload.mjs `
  --base-url "https://your-domain" `
  --token "your API Token" `
  --file "D:\test\image.png" `
  --channel s3 `
  --folder "photos/2026"

You can also place the token in an environment variable:

powershell
$env:IMGHOST_API_TOKEN="your API Token"
node imghost-token-single-upload.mjs --base-url "https://your-domain" --file "D:\test\image.png" --channel s3

Single-Request Parameters

ParameterRequiredDescription
--base-url <url>YesImgHost site URL, for example https://image.ai6.me.
--token <token>YesAPI Token. You can also use the IMGHOST_API_TOKEN environment variable.
--file <path>YesLocal file path.
--channel <key>YesUpload channel.
--folder <path>NoUpload folder, for example photos/2026 or /user/.
--name-type <type>NoNaming mode, mapped to backend uploadNameType. Defaults to default.
--channel-name <name>NoSelects a child channel/account. If omitted, the backend channel configuration decides.
--retries <n>NoTemporary failure retry count. Defaults to 3.
--timeout-ms <n>NoRequest timeout. Defaults to 180000.
--output <pretty|json>NoOutput format. Defaults to pretty.
--save-response <path>NoSave the final JSON response to a file.
--list-channelsNoList channels available to the current token and exit.

Single-Request Channels

Channel KeyChannel
telegram / tgTelegram
discord / dcDiscord
cfr2 / r2Cloudflare R2
s3S3
webdav / wdWebDAV storage channel
github / ghGitHub Releases
gitlab / glGitLab Packages
huggingface / hfHugging Face
onedrive / odOneDrive
googledrive / google / gdGoogle Drive
dropbox / dbDropbox
yandex / yxYandex Disk
pcloud / pdpCloud

Single-Request Size Limits

Keep single-request files under 100 MB where possible.

These channels have explicit single-request /upload blocking thresholds:

ChannelSingle-Request Limit
Telegram20 MiB
Discord10 MiB
S364 MiB
WebDAV64 MiB
GitHub Releases64 MiB
GitLab Packages64 MiB

When a file exceeds one of these limits, the script reports the matching error locally. Other channels do not have a hardcoded 100 MB local check in the script. If the request body exceeds Cloudflare or platform capacity, Cloudflare or the remote platform will return the error.

Chunked Upload

The chunked upload script first asks the backend to resolve the target file and then follows the large-file flow for the selected channel. You do not need to write chunk session, merge, or completion requests yourself.

powershell
node imghost-token-chunk-upload.mjs `
  --base-url "https://your-domain" `
  --token "your API Token" `
  --file "D:\test\video.zip" `
  --channel github `
  --folder "photos/2026" `
  --concurrency 3

Chunked Upload Parameters

ParameterRequiredDescription
--base-url <url>YesImgHost site URL.
--token <token>YesAPI Token. You can also use the IMGHOST_API_TOKEN environment variable.
--file <path>YesLocal file path.
--channel <key>YesUpload channel.
--folder <path>NoUpload folder.
--name-type <type>NoNaming mode, mapped to backend uploadNameType. Defaults to default.
--channel-name <name>NoSelects a child channel/account. If omitted, the backend channel configuration decides.
--concurrency <n>NoConcurrent uploads. Defaults to 1, maximum 3.
--retries <n>NoTemporary failure retry count. Defaults to 3.
--timeout-ms <n>NoPer-request timeout. Defaults to 180000.
--output <pretty|json>NoOutput format. Defaults to pretty.
--save-response <path>NoSave the final JSON response to a file.
--list-channelsNoList channels available to the current token and exit.

Chunked Upload Channels

Channel KeyUpload Flow
telegram / tgReal chunked /upload session
discord / dcReal chunked /upload session
cfr2 / r2Real chunked /upload session
github / ghReal chunked /upload session
gitlab / glReal chunked /upload session
webdav / wdReal chunked /upload session
s3S3 multipart upload
onedrive / odOneDrive upload session
googledrive / google / gdGoogle Drive resumable upload
dropbox / dbDropbox upload session
yandex / yxYandex direct upload URL
pcloud / pdpCloud upload link
huggingface / hfHugging Face LFS upload

Yandex compressed-file samples were unstable in testing. Non-compressed files have been verified to upload successfully.

Upload Response

After a successful upload, the script prints:

text
success
src: /file/photos/2026/example.png
url: https://your-domain/file/photos/2026/example.png
fileId: photos/2026/example.png
FieldDescription
srcInternal site file path.
urlFull public URL, suitable for your own scripts or database records.
fileIdFile ID, useful for later queries, management, or logs.
channelNameThe chunked script may return the actual child channel/account used.

With --output json, the script prints the full JSON response for programmatic use.

Direct Single-Request API Call

If you do not use the script, you can call the single-request upload endpoint directly:

text
POST https://your-domain/upload?uploadChannel=s3&uploadFolder=photos/2026&uploadNameType=default
Authorization: Bearer your API Token
Content-Type: multipart/form-data

Form field:

FieldRequiredDescription
fileYesFile to upload.

Query parameters:

ParameterRequiredDescription
uploadChannelYesReal upload channel.
uploadFolderNoUpload folder.
uploadNameTypeNoNaming mode.
channelNameNoSelects a child channel/account.

Successful responses look like this:

json
{
  "success": true,
  "src": "/file/photos/2026/example.png",
  "url": "https://your-domain/file/photos/2026/example.png",
  "fileId": "photos/2026/example.png"
}

FAQ

Large Single-Request Uploads Fail

Single-request /upload sends the whole file in one request. Large files may be blocked by Cloudflare or the remote platform. Use the chunked upload script for large files.

--channel-name Is Set But Upload Still Fails

Check that the selected channel really has a child channel with that name and that it is enabled. If --channel-name is omitted, the backend chooses an available account according to that channel's configuration.

I Want To Use The Result In Another Program

Use --output json, or add --save-response result.json. Read the url field to get the full file URL.

Yandex Cannot Upload Archives

Yandex does not support archive formats. This may be caused by their platform policy. When using Yandex, upload non-archive files where possible.

Released as user documentation for ImgHost.