File Upload Configuration#
Overview#
File upload size limits and batch counts in Dify flow through three tightly linked layers:
- Backend config (
FileUploadConfigclass) β the authoritative source of all limits, set via environment variables. - API endpoint (
GET /console/api/files/upload) β reads those values and exposes them as a JSON config object. - Frontend hook (
useFileSizeLimit) β consumes the API response and applies per-type size checks before upload.
1. Backend: FileUploadConfig#
All limits are declared in the FileUploadConfig class inside api/configs/feature/__init__.py. This class is a Pydantic BaseSettings mixin composed into the main FeatureConfig object, so every value can be overridden via environment variable.
| Env var | Default | Description |
|---|---|---|
UPLOAD_FILE_SIZE_LIMIT | 15 MB | General file uploads (docs, etc.) |
KNOWLEDGE_UPLOAD_FILE_SIZE_LIMIT_FOR_PAID_PLAN | 15 MB | Maximum allowed file size for knowledge uploads on paid cloud plans. On Dify Cloud, paid subscription plans (Professional, Team) use this limit instead of the default UPLOAD_FILE_SIZE_LIMIT when uploading files to knowledge bases. This allows paid users to upload larger files to their datasets. |
UPLOAD_IMAGE_FILE_SIZE_LIMIT | 10 MB | Image uploads |
UPLOAD_VIDEO_FILE_SIZE_LIMIT | 100 MB | Video uploads |
UPLOAD_AUDIO_FILE_SIZE_LIMIT | 50 MB | Audio uploads |
UPLOAD_SKILL_FILE_SIZE_LIMIT | 50 MB | Skill/plugin packages |
UPLOAD_FILE_BATCH_LIMIT | 5 | Max files per batch (console) |
BATCH_UPLOAD_LIMIT | 20 | Max files per batch upload operation |
WORKFLOW_FILE_UPLOAD_LIMIT | 10 | Max files in a workflow run upload |
IMAGE_FILE_BATCH_LIMIT | 10 | Max images per batch (knowledge base attachments) |
SINGLE_CHUNK_ATTACHMENT_LIMIT | 10 | Max attachments per chunk |
ATTACHMENT_IMAGE_FILE_SIZE_LIMIT | 2 MB | Image attachments in knowledge base chunks |
Package Archive Validation Limits#
These limits control the validation of .ifpkg archives during skill and agent package operations. They are enforced by SkillPackageService during skill package import/validation and by RosterPackageExporter during Roster Agent export. These bounds are separate from the standard file upload size limits and apply to archive structure and nested content.
| Env var | Default | Description |
|---|---|---|
SKILL_PACKAGE_MAX_UNCOMPRESSED_BYTES | 200 MB (209,715,200 bytes) | Maximum total uncompressed size of all files within a skill package archive |
SKILL_PACKAGE_MAX_ENTRIES | 5000 | Maximum number of entries (files + directories) allowed in a skill package archive |
SKILL_PACKAGE_MAX_SKILL_MD_BYTES | 1 MB (1,048,576 bytes) | Maximum size of the SKILL.md file within a skill package |
AGENT_PACKAGE_MAX_BYTES | 512 MB (536,870,912 bytes) | Maximum total size of a complete agent package archive (compressed) |
AGENT_PACKAGE_MAX_MANIFEST_BYTES | 5 MB (5,242,880 bytes) | Maximum size of each YAML document (app.yaml, manifest.yaml) within an agent package |
AGENT_PACKAGE_MAX_ENTRIES | 5000 | Maximum number of entries allowed in an agent package archive |
A computed field UPLOAD_FILE_EXTENSION_BLACKLIST parses the UPLOAD_FILE_EXTENSION_BLACKLIST env var (comma-separated, e.g. exe,bat,sh) into a set of lowercase extensions. By default the set is empty (all types allowed).
Canonical defaults are also shown in api/.env.example.
2. API: Config Exposure Endpoint#
GET /console/api/files/upload returns all current limits as a JSON payload. The handler reads directly from dify_config :
file_size_limit, knowledge_file_size_limit, batch_count_limit, file_upload_limit, image_file_size_limit, video_file_size_limit, audio_file_size_limit, skill_file_size_limit, workflow_file_upload_limit, image_file_batch_limit, single_chunk_attachment_limit, attachment_image_file_size_limit
The response schema is the UploadConfig Pydantic model from api/fields/file_fields.py.
knowledge_file_size_limit (int): Maximum file size in megabytes for knowledge base uploads for the current tenant. On paid plans (Professional, Team), this may be higher than file_size_limit. This value is determined by the tenant's subscription plan and the KNOWLEDGE_UPLOAD_FILE_SIZE_LIMIT_FOR_PAID_PLAN configuration.
POST /console/api/files/upload uploads a file. The controller calls FileService.upload_file, which enforces size limits and raises FileTooLargeError, UnsupportedFileTypeError, or BlockedFileExtensionError on validation failures.
When uploading files with source=datasets (knowledge base uploads), the system calls FeatureService.get_knowledge_file_size_limit(), which returns the larger of UPLOAD_FILE_SIZE_LIMIT and KNOWLEDGE_UPLOAD_FILE_SIZE_LIMIT_FOR_PAID_PLAN for paid plans (Professional, Team), or just UPLOAD_FILE_SIZE_LIMIT for free/sandbox plans. This limit is passed to FileService.upload_file as default_file_size_limit and applies to non-media file types (documents).
3. Frontend: useFileSizeLimit Hook#
The frontend fetches the config object from the API and stores it as FileUploadConfigResponse . The useFileSizeLimit hook in web/app/components/base/file-uploader/hooks.ts converts the MB values to bytes and falls back to hardcoded constants if the config is unavailable:
| Limit variable | Source field | Fallback constant |
|---|---|---|
imgSizeLimit | image_file_size_limit Γ 1 MiB | IMG_SIZE_LIMIT = 10 MB |
docSizeLimit | file_size_limit Γ 1 MiB | FILE_SIZE_LIMIT = 15 MB |
audioSizeLimit | audio_file_size_limit Γ 1 MiB | AUDIO_SIZE_LIMIT = 50 MB |
videoSizeLimit | video_file_size_limit Γ 1 MiB | VIDEO_SIZE_LIMIT = 100 MB |
skillSizeLimit | skill_file_size_limit Γ 1 MiB | SKILL_FILE_SIZE_LIMIT = 50 MB |
maxFileUploadLimit | workflow_file_upload_limit | MAX_FILE_UPLOAD_LIMIT = 10 |
Fallback constants are defined in web/app/components/base/file-uploader/constants.ts.
The checkSizeLimit callback (returned by useFile) dispatches on SupportUploadFileTypes (image / document / audio / video / custom) and shows a toast error if the file exceeds the applicable limit, blocking the upload. This check runs for both local file picks and remote URL pastes .
Data Flow Diagram#
env vars
βββΊ FileUploadConfig (api/configs/feature/__init__.py)
βββΊ dify_config.UPLOAD_*
βββΊ GET /console/api/files/upload
βββΊ FileUploadConfigResponse (web/models/common.ts)
βββΊ useFileSizeLimit() β checkSizeLimit()
βββΊ toast error / block upload
Key Source Files#
| File | Role |
|---|---|
api/configs/feature/__init__.py | FileUploadConfig β all limit defaults & env var declarations |
api/.env.example | Canonical env var reference with defaults |
api/controllers/console/files.py | /files/upload GET handler that exposes config; POST handler that validates uploads |
api/fields/file_fields.py | UploadConfig response schema |
web/models/common.ts | FileUploadConfigResponse frontend type |
web/app/components/base/file-uploader/hooks.ts | useFileSizeLimit + checkSizeLimit β frontend validation |
web/app/components/base/file-uploader/constants.ts | Hardcoded fallback limits |