Skip to content

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

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 None DocType this file is attached to -
attached_to_name None Document ID this file is attached to -
is_private bool If True, requires authentication -
Role Create Delete Read Write
Guest
User
Setting Value
Submittable False
Track Changes True

Controller hooks are implemented in *_controller.py files. Available lifecycle hooks:

  • validate() - Called before save, raise exceptions for validation errors
  • before_insert() - Called before inserting a new document
  • after_insert() - Called after successfully inserting
  • before_save() - Called before saving (insert or update)
  • after_save() - Called after saving
  • before_delete() - Called before deleting
  • after_delete() - Called after deleting