import requests


def create_short_url(api_key, long_url, project_name='cannlytics'):
    """Create a short URL to a specified file."""
    try:
        url = f'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key={api_key}'
        data= {
            'dynamicLinkInfo': {
                'domainUriPrefix': f'https://{project_name}.page.link',
                'link': long_url,
            },
            'suffix': {'option': 'UNGUESSABLE'}
        }
        response = requests.post(url, json=data)
        return response.json()['shortLink']
    except ConnectionError:
        raise ConnectionError