def preprocess_incoming_content(content, encrypt_func, max_size_bytes):
    """
    Apply preprocessing steps to file/notebook content that we're going to
    write to the database.

    Applies ``encrypt_func`` to ``content`` and checks that the result is
    smaller than ``max_size_bytes``.
    """
    encrypted = encrypt_func(content)
    if max_size_bytes != UNLIMITED and len(encrypted) > max_size_bytes:
        raise FileTooLarge()
    return encrypted