File
File attachment DocType.
Stores metadata about uploaded files. Actual file content
is stored via StorageAdapter (local, S3, GCS, etc.).
Attributes:
file_name: Original filename as uploaded
file_url: Storage URL/path for retrieval
file_size: Size in bytes
content_type: MIME type (e.g., "application/pdf")
attached_to_doctype: DocType this file is attached to
attached_to_name: Document ID this file is attached to
is_private: If True, requires authentication to access
Example:
file = File(
file_name="report.pdf",
file_url="/files/2024/01/report-abc123.pdf",
file_size=51200,
content_type="application/pdf",
is_private=True,
)
Source: file.py
Fields
| Field | Type | Required | Description | Validators |
|---|---|---|---|---|
| file_name | str | Original filename | - | |
| file_url | str | Storage URL/path | - | |
| file_size | int | File size in bytes | - | |
| content_type | str | MIME type | - | |
| attached_to_doctype | str | None | DocType this file is attached to | |
| attached_to_name | str | None | Document ID this file is attached to | |
| is_private | bool | If True, requires authentication | - |
Permissions
| Role | Create | Delete | Read | Write |
|---|---|---|---|---|
| Guest | ✓ | |||
| User | ✓ | ✓ | ✓ | ✓ |
Configuration
| Setting | Value |
|---|---|
| Submittable | False |
| Track Changes | True |
Controller
Controller hooks are implemented in *_controller.py files.
Available lifecycle hooks:
validate()- Called before save, raise exceptions for validation errorsbefore_insert()- Called before inserting a new documentafter_insert()- Called after successfully insertingbefore_save()- Called before saving (insert or update)after_save()- Called after savingbefore_delete()- Called before deletingafter_delete()- Called after deleting