0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-24 10:58:52 +01:00
wagtail/docs/advanced_topics/documents/storing_and_serving.md
Neeraj P Yetheendran 8932c67270 Add full set of Documents app features
- Added customizing document upload form subsection in documents section
- Added storing and serving subpage
- Added overview section, including RichText and StreamField usage
- Closes #2001
2023-11-13 09:53:16 +11:00

2.3 KiB
Raw Blame History

(storing_and_serving)=

Storing and serving

Wagtail follows Djangos conventions for managing uploaded files. For configuration of FileSystemStorage and more information on handling user uploaded files, see .

File storage location

Wagtail uses the DEFAULT_FILE_STORAGE setting to determine where and how user-uploaded files are stored. By default, Wagtail stores files in the local filesystem.

Serving documents

Document serving is controlled by the WAGTAILDOCS_SERVE_METHOD method. It provides a number of serving methods which trade some of the strictness of the permission check that occurs when normally handling a document request for performance.

The serving methods provided are direct, redirect and serve_view, with redirect method being the default when WAGTAILDOCS_SERVE_METHOD is unspecified or set to None. For example:

WAGTAILDOCS_SERVE_METHOD = "redirect"

Content types

Wagtail provides the WAGTAILDOCS_CONTENT_TYPES setting to specify which document content types are allowed to be uploaded. For example:

WAGTAILDOCS_CONTENT_TYPES = {
    'pdf': 'application/pdf',
    'txt': 'text/plain',
}

Inline content types

Inline content types can be specified using WAGTAILDOCS_INLINE_CONTENT_TYPES, are displayed within the rich text editor.

For example:

WAGTAILDOCS_INLINE_CONTENT_TYPES = ['application/pdf', 'text/plain']

File extensions

Wagtail allows you to specify the permitted file extensions for document uploads using the WAGTAILDOCS_EXTENSIONS setting.

It also validates the extensions using Django's FileExtensionValidator. For example:

WAGTAILDOCS_EXTENSIONS = ['pdf', 'docx']

Document password required template

Wagtail provides the DOCUMENT_PASSWORD_REQUIRED_TEMPLATE setting to use a custom template when a password is required to access a protected document. Read more about .

Here's an example:

DOCUMENT_PASSWORD_REQUIRED_TEMPLATE = 'myapp/document_password_required.html'