from typing import Optional


def extract_filename_from_object_info(object_info: dict) -> Optional[str]:
    """Extracts the filename from the object_info.

    if filename is in object_info use that, otherwise try to extract it from the one of the access methods.
    Returns filename if found, else return None

    Args
        object_info (dict): DRS object dictionary
    """
    if "name" in object_info and object_info["name"]:
        return object_info["name"]

    for access_method in object_info["access_methods"]:
        url = access_method["access_url"]["url"]
        parts = url.split("/")
        if parts:
            return parts[-1]

    return None