from pathlib import Path


def format_relative_dirname(directory: Path, base_directory: Path) -> str:
    """Formats a relative directory path in a way that's compatible with the
    presigned POST URLs.

    Parameters
    ----------
    directory : `pathlib.Path`
        The directory to compute a relative path/name for.
    base_directory : `pathlib.Path`
        The base directory.

    Returns
    -------
    name : `str`
        The relative directory name.

        Examples:

        - ``"base/`` relative to ``"/base/"`` is ``"/"``.
        - ``"base/a/`` relative to ``"/base/"`` is ``"a/"``.
        - ``"base/a/b`` relative to ``"/base/"`` is ``"a/b/"``.
    """
    name = str(directory.relative_to(base_directory))
    if name == ".":
        return "/"
    elif not name.endswith("/"):
        return name + "/"
    else:
        return name