import base64


def img_stream_to_b64str(stream, urlsafe=False):
    """
    Convert a byte stream of image file to Base64 encoded string.
    :param stream: The byte stream of the file.
    :param urlsafe: Trigger using URL-Safe format.
    :return: Encoded Base64 string.
    """
    if urlsafe:
        stream_base64 = base64.urlsafe_b64encode(stream)
    else:
        stream_base64 = base64.standard_b64encode(stream)

    stream_base64_string = stream_base64.decode('utf-8')

    return stream_base64_string