Skip to content

oarepo_config.files

oarepo_config.files

Configuration for record files and upload quotas.

configure_files(max_file_size: int = 1 * 10 ** 9, max_files_count: int = 100, max_total_size: int = 5 * 10 ** 9, allow_metadata_only_records: bool = True, allow_empty_files: bool | None = None, file_modification_grace_period: timedelta = timedelta(days=45), allow_immediate_file_modification: bool = True, allow_immediate_quota_increase: bool = True, max_additional_quota_size: int = 0, allow_archive_download: bool = True, max_archive_download_size: int | None = None) -> None

Set up file upload quotas and file-related toggles.

Controls how many files users may attach to a record deposition, how large each individual file may be, the total storage budget for the deposition, whether a deposition can be published without any files at all, and whether uploaded files may have zero bytes.

Parameters:

Name Type Description Default
max_file_size int

Maximum size of a single uploaded file in bytes. Defaults to 1 GB (1 * 10**9).

1 * 10 ** 9
max_files_count int

Maximum number of files allowed per record deposition. Defaults to 100.

100
max_total_size int

Maximum combined size of all files in a single record deposition, in bytes. Defaults to 5 GB (5 * 10**9).

5 * 10 ** 9
allow_metadata_only_records bool

When False, users must upload at least one file before they can publish a record deposition. When True (the default), metadata-only records are allowed.

True
allow_empty_files bool | None

When False, zero-byte files are rejected. When True, they are allowed. Defaults to the value of allow_metadata_only_records so that requiring files also prevents users from satisfying the requirement with an empty file.

None
file_modification_grace_period timedelta

Grace period after a record is published during which its files can still be modified without creating a new version. Checked at publish time. Defaults to 45 days (timedelta(days=45)).

timedelta(days=45)
allow_immediate_file_modification bool

When True (the default), record owners may unlock and edit their published files themselves within file_modification_grace_period, while admins and system processes may do so at any time. When False, the default Invenio policy (admin-only) is left in place.

True
allow_immediate_quota_increase bool

When True (the default), users may immediately raise a draft's storage quota from their additional allowance (this surfaces the "Manage storage" UI in the file uploader); admins may do so for any record. When False, immediate quota increases stay disabled.

True
max_additional_quota_size int

Additional quota users/admins may grant on top of the default record quota. Defaults to 0.

0
allow_archive_download bool

Whether all files of a record can be downloaded at once as a single ZIP archive ("Download all"). The archive is assembled on the fly by a web worker, which stays busy for the whole download. Defaults to True.

True
max_archive_download_size int | None

Largest total size of a record's files, in bytes, for which the "Download all" archive is still offered; larger records only offer per-file downloads. None (the default, same as upstream InvenioRDM) means no limit - set one if your repository accepts large files (Zenodo uses 300 MB, 300 * 10**6).

None

Invenio configuration variables set:

  • RDM_FILES_DEFAULT_MAX_FILE_SIZE - backend limit on the size of a single file.
  • RDM_FILES_DEFAULT_QUOTA_SIZE - backend limit on the total size of all files in a record deposition.
  • RDM_RECORDS_MAX_FILES_COUNT - backend limit on the number of files per record.
  • RDM_ALLOW_METADATA_ONLY_RECORDS - whether metadata-only records are allowed.
  • RECORDS_RESOURCES_ALLOW_EMPTY_FILES - whether zero-byte files may be uploaded.
  • RDM_FILE_MODIFICATION_PERIOD - time window after record creation during which modified files may be published.
  • RDM_IMMEDIATE_FILE_MODIFICATION_ENABLED - whether published files may be edited immediately; set to allow_immediate_file_modification.
  • RDM_IMMEDIATE_FILE_MODIFICATION_POLICIES - ordered list of policies deciding who may edit published files immediately (only set when allow_immediate_file_modification is True).
  • RDM_IMMEDIATE_QUOTA_INCREASE_ENABLED - whether users may immediately raise a draft's quota; set to allow_immediate_quota_increase.
  • RDM_IMMEDIATE_QUOTA_INCREASE_POLICIES - ordered list of policies deciding who may raise a draft's quota (only set when allow_immediate_quota_increase is True).
  • APP_RDM_DEPOSIT_FORM_QUOTA - deposit-form UI quota object with maxFiles and maxStorage.
  • FILES_REST_DEFAULT_MAX_FILE_SIZE and FILES_REST_DEFAULT_QUOTA_SIZE - fallback variables used by the lower-level file storage layer.
  • RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE - the max_additional_quota_size above.
  • RDM_ARCHIVE_DOWNLOAD_ENABLED - whether the "Download all" archive is available.
  • RECORDS_RESOURCES_ARCHIVE_DOWNLOAD_MAX_SIZE - total size limit for the "Download all" archive.
Example
# Use the default file quotas and toggles. All parameters below
# match the helper's built-in defaults and are shown explicitly
# for reference; they can be omitted when calling the helper.
config.configure_files(
    max_file_size=1 * 10**9,
    max_files_count=100,
    max_total_size=5 * 10**9,
    allow_metadata_only_records=True,
)
Source code in oarepo_config/files.py
def configure_files(  # noqa: PLR0913, PLR0917
    max_file_size: int = 1 * 10**9,
    max_files_count: int = 100,
    max_total_size: int = 5 * 10**9,
    allow_metadata_only_records: bool = True,
    allow_empty_files: bool | None = None,
    file_modification_grace_period: timedelta = timedelta(days=45),
    allow_immediate_file_modification: bool = True,
    allow_immediate_quota_increase: bool = True,
    max_additional_quota_size: int = 0,
    allow_archive_download: bool = True,
    max_archive_download_size: int | None = None,
) -> None:
    """Set up file upload quotas and file-related toggles.

    Controls how many files users may attach to a record deposition, how
    large each individual file may be, the total storage budget for the
    deposition, whether a deposition can be published without any files
    at all, and whether uploaded files may have zero bytes.

    Args:
        max_file_size: Maximum size of a single uploaded file in bytes.
            Defaults to 1 GB (`1 * 10**9`).
        max_files_count: Maximum number of files allowed per record
            deposition. Defaults to `100`.
        max_total_size: Maximum combined size of all files in a single
            record deposition, in bytes. Defaults to 5 GB
            (`5 * 10**9`).
        allow_metadata_only_records: When `False`, users must upload
            at least one file before they can publish a record
            deposition. When `True` (the default), metadata-only
            records are allowed.
        allow_empty_files: When `False`, zero-byte files are rejected.
            When `True`, they are allowed. Defaults to the value of
            `allow_metadata_only_records` so that requiring files also
            prevents users from satisfying the requirement with an empty
            file.
        file_modification_grace_period: Grace period after a record is
            published during which its files can still be modified without
            creating a new version. Checked at publish time. Defaults to
            45 days (`timedelta(days=45)`).
        allow_immediate_file_modification: When `True` (the default),
            record owners may unlock and edit their published files
            themselves within `file_modification_grace_period`, while
            admins and system processes may do so at any time. When
            `False`, the default Invenio policy (admin-only) is left in
            place.
        allow_immediate_quota_increase: When `True` (the default), users
            may immediately raise a draft's storage quota from their
            additional allowance (this surfaces the "Manage storage" UI in
            the file uploader); admins may do so for any record. When
            `False`, immediate quota increases stay disabled.
        max_additional_quota_size: Additional quota users/admins may grant
            on top of the default record quota. Defaults to 0.
        allow_archive_download: Whether all files of a record can be
            downloaded at once as a single ZIP archive ("Download all").
            The archive is assembled on the fly by a web worker, which
            stays busy for the whole download. Defaults to `True`.
        max_archive_download_size: Largest total size of a record's files,
            in bytes, for which the "Download all" archive is still
            offered; larger records only offer per-file downloads. `None`
            (the default, same as upstream InvenioRDM) means no limit - set
            one if your repository accepts large files (Zenodo uses
            300 MB, `300 * 10**6`).

    Invenio configuration variables set:

    * `RDM_FILES_DEFAULT_MAX_FILE_SIZE` - backend limit on the size of
      a single file.
    * `RDM_FILES_DEFAULT_QUOTA_SIZE` - backend limit on the total size
      of all files in a record deposition.
    * `RDM_RECORDS_MAX_FILES_COUNT` - backend limit on the number of
      files per record.
    * `RDM_ALLOW_METADATA_ONLY_RECORDS` - whether metadata-only
      records are allowed.
    * `RECORDS_RESOURCES_ALLOW_EMPTY_FILES` - whether zero-byte files
      may be uploaded.
    * `RDM_FILE_MODIFICATION_PERIOD` - time window after record
      creation during which modified files may be published.
    * `RDM_IMMEDIATE_FILE_MODIFICATION_ENABLED` - whether published
      files may be edited immediately; set to
      `allow_immediate_file_modification`.
    * `RDM_IMMEDIATE_FILE_MODIFICATION_POLICIES` - ordered list of
      policies deciding who may edit published files immediately (only
      set when `allow_immediate_file_modification` is `True`).
    * `RDM_IMMEDIATE_QUOTA_INCREASE_ENABLED` - whether users may
      immediately raise a draft's quota; set to
      `allow_immediate_quota_increase`.
    * `RDM_IMMEDIATE_QUOTA_INCREASE_POLICIES` - ordered list of policies
      deciding who may raise a draft's quota (only set when
      `allow_immediate_quota_increase` is `True`).
    * `APP_RDM_DEPOSIT_FORM_QUOTA` - deposit-form UI quota object with
      `maxFiles` and `maxStorage`.
    * `FILES_REST_DEFAULT_MAX_FILE_SIZE` and
      `FILES_REST_DEFAULT_QUOTA_SIZE` - fallback variables used by
      the lower-level file storage layer.
    * `RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE` - the
      `max_additional_quota_size` above.
    * `RDM_ARCHIVE_DOWNLOAD_ENABLED` - whether the "Download all"
      archive is available.
    * `RECORDS_RESOURCES_ARCHIVE_DOWNLOAD_MAX_SIZE` - total size limit
      for the "Download all" archive.

    Example:
        ```python
        # Use the default file quotas and toggles. All parameters below
        # match the helper's built-in defaults and are shown explicitly
        # for reference; they can be omitted when calling the helper.
        config.configure_files(
            max_file_size=1 * 10**9,
            max_files_count=100,
            max_total_size=5 * 10**9,
            allow_metadata_only_records=True,
        )
        ```

    """
    RDM_FILES_DEFAULT_MAX_FILE_SIZE = max_file_size
    FILES_REST_DEFAULT_MAX_FILE_SIZE = max_file_size

    RDM_FILES_DEFAULT_QUOTA_SIZE = max_total_size
    FILES_REST_DEFAULT_QUOTA_SIZE = max_total_size

    RDM_RECORDS_MAX_FILES_COUNT = max_files_count

    RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE = max_additional_quota_size

    APP_RDM_DEPOSIT_FORM_QUOTA = {
        "maxFiles": max_files_count,
        "maxStorage": max_total_size,
    }

    RDM_ALLOW_METADATA_ONLY_RECORDS = allow_metadata_only_records
    RECORDS_RESOURCES_ALLOW_EMPTY_FILES = (
        allow_empty_files if allow_empty_files is not None else allow_metadata_only_records
    )

    RDM_ARCHIVE_DOWNLOAD_ENABLED = allow_archive_download
    RECORDS_RESOURCES_ARCHIVE_DOWNLOAD_MAX_SIZE = max_archive_download_size

    RDM_FILE_MODIFICATION_PERIOD = file_modification_grace_period

    RDM_IMMEDIATE_FILE_MODIFICATION_ENABLED = allow_immediate_file_modification
    if allow_immediate_file_modification:
        # Let record owners unlock/edit their published files themselves within
        # the grace period; admins/system may do so at any time. Policies are
        # evaluated in order, most to least specific.
        RDM_IMMEDIATE_FILE_MODIFICATION_POLICIES = [
            FileModificationGracePeriodPolicy(grace_period=file_modification_grace_period),
            FileModificationAdminPolicy(),
        ]

    RDM_IMMEDIATE_QUOTA_INCREASE_ENABLED = allow_immediate_quota_increase
    if allow_immediate_quota_increase:
        # Let users raise a draft's quota from their additional allowance
        # immediately (surfaces the "Manage storage" UI); admins for any record.
        RDM_IMMEDIATE_QUOTA_INCREASE_POLICIES = [
            QuotaIncreasePolicy(),
            QuotaIncreaseAdminPolicy(),
        ]

    set_constants_in_caller(locals())