def download_file_by_id(box_client: BoxClient, box_file: File, temp_dir: str) -> str:
    """
    Downloads a Box file to the specified temporary directory.

    Args:
        box_client (BoxClient): An authenticated Box client object.
        box_file (BoxFile): The Box file object to download.
        temp_dir (str): The path to the temporary directory where the file
            will be downloaded.

    Returns:
        str: The path to the downloaded file on success.
        If an error occurs during download, returns the error message.

    Raises:
        BoxAPIError: If an error occurs while interacting with the Box API.

    """
    # Save the downloaded file to the specified local directory.
    file_path = os.path.join(temp_dir, box_file.name)

    try:
        file_stream: ByteStream = box_client.downloads.download_file(box_file.id)
    except BoxAPIError as e:
        logger.error(f"An error occurred while downloading file: {e}", exc_info=True)
        return e.message

    logger.info(f"Downloading file: {box_file.id} {box_file.name} ")
    with open(file_path, "wb") as file:
        shutil.copyfileobj(file_stream, file)

    return file_path

    Downloads a Box file to the specified temporary directory.

    Args:
        box_client (BoxClient): An authenticated Box client object.
        box_file (BoxFile): The Box file object to download.
        temp_dir (str): The path to the temporary directory where the file
            will be downloaded.

    Returns:
        str: The path to the downloaded file on success.
        If an error occurs during download, returns the error message.

    Raises:
        BoxAPIError: If an error occurs while interacting with the Box API.

    
llama-index-integrations/readers/llama-index-readers-box/llama_index/readers/box/BoxAPI/box_api.py