import uuid
import base64


def generate_url_safe_filename(extension='png'):
    """Generate URL-safe random filename based on UUID4."""
    name = uuid.uuid4()
    filename = base64.urlsafe_b64encode(
        name.bytes).decode('utf-8').rstrip('=\n')
    return '{filename}.{extension}'.format(
        filename=filename, extension=extension)